getting my variable on my MsgBox

Started by
5 comments, last by firecast 20 years, 5 months ago
A little newbie question... how do i convert a number (int or DWORD), so i can see it on a MessageBox without getting a conversion-type error?? thanks in advance
This really pisses me off!!
Advertisement
quote:Original post by firecast
A little newbie question...

how do i convert a number (int or DWORD), so i can see it on a MessageBox without getting a conversion-type error??

thanks in advance


Declare a buffer, and use wsprintf.
char  buffer[1024];wsprintf(buffer, "%d", MyValue);MessageBox(window, buffer, "...", MB_OK 
or simply do
MessageBox(window, itoa(MyValue, 10), "...", MB_OK);
Matt
or you could try string stream
#include "strstream"using namespace std;strstream sstr;int i, n;sstr << i << "string" << n << ends;MessageBox... sstr.str() 


string stream will convert all compatible types you stream to it into a single string.
strstream is deprecated, use stringstream instead. The syntax is exactly the same as with strstream, except you should include sstream instead of strstream.

- neophyte
well, thank you all.... that was fast
This really pisses me off!!
You can also use a switch statement.

switch(MessageBox(NULL, "text", "title", MB_YESNO)){  case ID_YES:   //do yes command stuff here  break;  case ID_NO:   //do no command stuff here  break;}

This topic is closed to new replies.

Advertisement