Thread: Dev C++ and Strings

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    14

    Dev C++ and Strings

    I am using dev c++ and it doesnt like strings for me like:
    PHP Code:
    #include <string>

    ....


    string word;
    word "hi"
    I get alot of errors with code similar to that. Anyone else have these problems ?

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Code:
    #include <string>
    
    ....
    
    std::string word;
    word = "hi";
    If that doesn't work then post more code, preferably a complete compilable program that we can work with and figure out your problem in a way that is better than guessing.

    -Prelude
    My best code is written with the delete key.

  3. #3
    Registered User bljonk's Avatar
    Join Date
    Oct 2001
    Posts
    70

    Dev-C++ 5 beta 3

    yeah! namespaces are a factor there~

    which version are you using anyways?
    Ünicode¬>world = 10.0£

  4. #4
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    another option!!

    Code:
    #include <string>
    using namespace std;
    ....
    
    string word;
    word = "hi";

    or even....

    Code:
    #include <string>
    using std::string;
    ....
    
    string word;
    word = "hi";

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    52
    Although it's been a while since I've used Dev....there are a couple of things that I think might help your malaise...

    First, try using namespace std;...
    Second, append a '.h' to the end of your #include string file
    i.e. #include <string.h>

    This might help, hope it does.
    MS VC++ 6.0

  6. #6
    Registered User
    Join Date
    Jul 2002
    Posts
    14
    k im making a guessing game and heres the code:

    PHP Code:
    #include <windows.h>
    #include <stdlib.h>
    #include <string>

    HINSTANCE hInstGlobal;
    HWND hEdit;

    /* Declare Windows procedure */
    LRESULT CALLBACK WindowProcedure(HWNDUINTWPARAMLPARAM);
    /* Make the class name into a global variable */
    char szClassName[ ] = "WindowsApp";
    int WINAPI WinMain(HINSTANCE hThisInstanceHINSTANCE hPrevInstanceLPSTR lpszArgumentint nFunsterStil)

    {
        
    HWND hwnd;               /* This is the handle for our window */
        
    MSG messages;            /* Here messages to the application are saved */
        
    WNDCLASSEX wincl;        /* Data structure for the windowclass */

        /* The Window structure */
        
    wincl.hInstance hThisInstance;
        
    wincl.lpszClassName szClassName;
        
    wincl.lpfnWndProc WindowProcedure;      /* This function is called by windows */
        
    wincl.style CS_DBLCLKS;                 /* Catch double-clicks */
        
    wincl.cbSize sizeof(WNDCLASSEX);

        
    /* Use default icon and mouse-pointer */
        
    wincl.hIcon LoadIcon(NULLIDI_APPLICATION);
        
    wincl.hIconSm LoadIcon(NULLIDI_APPLICATION);
        
    wincl.hCursor LoadCursor(NULLIDC_ARROW);
        
    wincl.lpszMenuName NULL/* No menu */
        
    wincl.cbClsExtra 0;                      /* No extra bytes after the window class */
        
    wincl.cbWndExtra 0;                      /* structure or the window instance */
        /* Use light-gray as the background of the window */
        
    wincl.hbrBackground = (HBRUSHGetStockObject(WHITE_BRUSH);

        
    /* Register the window class, if fail quit the program */
        
    if(!RegisterClassEx(&wincl)) return 0;

        
    /* The class is registered, let's create the program*/
        
    hwnd CreateWindowEx(
               
    0,                   /* Extended possibilites for variation */
               
    szClassName,         /* Classname */
               
    "GuessingGame",         /* Title Text */
               
    WS_OVERLAPPEDWINDOW/* default window */
               
    CW_USEDEFAULT,       /* Windows decides the position */
               
    CW_USEDEFAULT,       /* where the window ends up on the screen */
               
    320,                 /* The programs width */
               
    100,                 /* and height in pixels */
               
    HWND_DESKTOP,        /* The window is a child-window to desktop */
               
    NULL,                /* No menu */
               
    hThisInstance,       /* Program Instance handler */
               
    NULL                 /* No Window Creation data */
               
    );

        
    /* Make the window visible on the screen */
        
    ShowWindow(hwndnFunsterStil);
        
    /* Run the message loop. It will run until GetMessage( ) returns 0 */
        
    while(GetMessage(&messagesNULL00))
        {
               
    /* Translate virtual-key messages into character messages */
               
    TranslateMessage(&messages);
               
    /* Send message to WindowProcedure */
               
    DispatchMessage(&messages);
        }

        
    /* The program return-value is 0 - The value that PostQuitMessage( ) gave */
        
    return messages.wParam;
    }

    /* This function is called by the Windows function DispatchMessage( ) */
    LRESULT CALLBACK WindowProcedure(HWND hwndUINT messageWPARAM wParamLPARAM lParam)
    {
        switch (
    message)                  /* handle the messages */
        
    {
               case 
    WM_DESTROY:
               
    PostQuitMessage(0);        /* send a WM_QUIT to the message queue */
               
    break;
               case 
    WM_CREATE:
               
    HWND hButton,bButton;
               
    hButton CreateWindow("BUTTON","Guess",WS_CHILD WS_VISIBLE BS_PUSHBUTTON220,30,80,20,hwnd,(HMENU1,hInstGlobal,NULL);
               
    bButton CreateWindow("BUTTON","New Topic",WS_CHILD WS_VISIBLE BS_PUSHBUTTON,220,10,80,20,hwnd,(HMENU2,hInstGlobal,NULL);
               
    hEdit CreateWindow("EDIT","GuessingGame",WS_CHILD WS_VISIBLE WS_BORDER ES_AUTOHSCROLL,10,30,200,20,hwnd,(HMENU1,hInstGlobal,NULL);
               case 
    WM_PAINT:
               
    HFONT hFont;
               
    HDC hdc;
               
    PAINTSTRUCT ps;
               
    hdc BeginPaint(hwnd,&ps);

               
    hFont = (HFONTGetStockObject (SYSTEM_FONT);
               
    SelectObject (hdc,hFont);
               
    SetTextColor(hdc,RGB(0,0,255));
               
    SetTextAlign(hdc,TA_LEFT);
               
    //error here
               
    string word;


               
    TextOut(hdc,10,10,"topic",5);
               default:                   
    /* for messages that we don't deal with */
               
    return DefWindowProc(hwndmessagewParamlParam);
        }
        return 
    0;


  7. #7
    Registered User
    Join Date
    May 2002
    Posts
    66
    See replies above on how to fix it...

  8. #8
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    >>
    First, try using namespace std;...
    Second, append a '.h' to the end of your #include string file
    <<

    There is no need for using namespace std; if you have a .h at the end.
    "There are three kinds of people in the world...
    Those that can count and those that can't."

  9. #9
    flashing vampire black's Avatar
    Join Date
    May 2002
    Posts
    563

    Smile Re: Dev C++ and Strings

    Originally posted by The-Guy
    I am using dev c++ and it doesnt like strings for me like:
    PHP Code:
    #include <string>

    ....


    string word;
    word "hi"
    I get alot of errors with code similar to that. Anyone else have these problems ?
    May be some other mistakes. my compiler works fine with that code. my soft is also Dev-C++, version 4.9.3.0

    PHP Code:
    #include <iostream>
    #include <string>

    void main()
    {
      
    string word;
      
    word="Hello World~";
      
    cout << word << endl;
      
    cin >> "what";

    Never end on learning~

Popular pages Recent additions subscribe to a feed