-
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'
-
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());
-
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).