sstream and LPSTR

This is a discussion on sstream and LPSTR within the C++ Programming forums, part of the General Programming Boards category; I need to convert a str value from a sstream to LPSTR but I have no clue how. Hers my ...

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    731

    sstream and LPSTR

    I need to convert a str value from a sstream to LPSTR but I have no clue how.

    Hers my code:

    Code:
            float currenttime = (float)GetTickCount();
            float deltatime = currenttime - lasttime * 0.001f;
            outs << deltatime;
            LPSTR test = outs.str();  //Error line
            SetWindowText(eng.window, test);
    The error says:

    error C2440: 'initializing' : cannot convert from 'std::basic_ostringstream<_Elem,_Traits,_Alloc>::_ Mystr' to 'LPSTR'

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    a couple ways to solve your problem - neither use LPSTR
    Code:
    		std::string test = outs.str();  
    		SetWindowText(eng.window, test.c_str());
      OR
    		SetWindowText(eng.window, outs.str().c_str());

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,340
    str().c_str() will return a const char*, which is what LPCSTR is. This is different than LPSTR, which is just a char*.

    In this case it should be ok, since SetWindowText actually takes an LPCTSTR (which is just an LPCSTR for your program if you don't use Unicode).

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21