Write in MessageBox

How can i write in Messagebox double or int numbers ?
I want to do like this...
//...
string s1="You have ";
string s2=" messages.";
string s;
for(int i= 0 ;i<10;i++)
{
stringstream os;
os<<i;
s=s1+os.str()+s2;
MessageBox(NULL,...,L"Blah blah",MB_YESNO);

}

//...

What should i write instead of ...?
How can I convert from string to const wcar_t * ?
Please tell me
P.S. And sorry for my english.

You already have an std::string, so use its c_str() method.

std::string
http://www.cplusplus.com/reference/string/string/

std::string::c_str()
http://www.cplusplus.com/reference/string/string/c_str/
Last edited on
I know that but MessageBox wants const wchar_t * not const char *...
error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char *' to 'LPCWSTR'
MessageBox is #defined to either MessageBoxW when compiling in UNICODE mode,
or MessageBoxA when compiling in NON UNICODE mode.

In your case change MessageBox to read MessageBoxA - that will use the NON UNICODE
version of the function.
Thanx very much that helps me but however when i compile with visual studio 6.0 i can write in message box
MessageBox(NULL,s.c_str(),L"Blah blah",MB_YESNO);
and i havn't got any errors but when i compile with vs 9.0 i've got an error.
What happens if you write
MessageBoxA(NULL,s.c_str(), "Blah blah",MB_YESNO); //notice the L is removed
That works fine
when i compile with visual studio 6.0 i can write in message box
MessageBox(NULL,s.c_str(),L"Blah blah",MB_YESNO);
and i havn't got any errors but when i compile with vs 9.0 i've got an error.


VS6 is not defaulting to Unicode.

VS9 is.

MessageBox(NULL,s.c_str(),L"Blah blah",MB_YESNO); is wrong in any event. guestgulkan is correct -- you should be using MessageBoxA.

See this for details:

http://www.cplusplus.com/forum/articles/16820/
Either use MessageBoxA, std::string and std::stringstream or use MessageBoxW, std::wstring and std::wstringstream together.
Topic archived. No new replies allowed.