L"string"

Hi,
There is a L"mystring". What to do if i have:
string s = "mystring";
Messagebox(NULL, ??? s, ...);

How to do the same thing as L"Mystring" with variable?
1
2
wstring s = L"mystring";
MessageBoxW(NULL, s.c_str(), ... );


wstring uses wchar_t instead of char.

also note MessageBoxW and not MessageBox: http://cplusplus.com/forum/articles/16820/
1
2
std::wstring s=L"somestring";
MessageBox(/*...*/,s.c_str(),/*...*/);


But the proper way would be to use the TEXT macro for string literals:
MessageBox(/*...*/,TEXT("somestring"),/*...*/);
Or, to test whether UNICODE was defined.

EDIT: Oh, you sonova...
Last edited on
Thanks for answers, it helped a bit. I got the conversion by writing:
wstring str = L"mystring";
MessageBoxW(NULL, str.c_str(), ...);

TEXT("something") also works fine, but only with constants written directly in it, becouse it puts L to anything what is written inside (as far as i tried).

But the thing is i have constructed a string by using stringstream. How can i convert it to make it show in the messagebox? My code:

stringstream errorMsg;
errorMsg << "Call to " << (char *)whichFunc << " returned error " << errorCode << "!";
MessageBoxW(NULL, ???->errorMsg, TEXT("socketIndication"), MB_OK);
Topic archived. No new replies allowed.