What is the problem with the following code?
MessageBox(NULL,"The number is: "x,"Msg",MB_OK);
(x is the integer variable)
What is the problem with the following code?
MessageBox(NULL,"The number is: "x,"Msg",MB_OK);
(x is the integer variable)
You need to add a comma before starting the argument list.
MessageBox(NULL,"The number is: ",x,"Msg",MB_OK);
Spidey out!
Except I don't think you can have five arguments, can you?
You'll need to build a string that has the information you want to use in it. Since you posted this in C++, probably that means you want to use a stringstream.
I tried to copy the integer into the string usingbut it didnt work.Code:strcat(text, x);
What am I doing wrong?
strcat() copies one string to another, to use it, you have to convert your int into string from. It's easiest to use the STL, but you can use something like sprintf() to itoa() if you want to.
Spidey, out of curiosity, do you know how to program C/C++?
Read this.
Here's an example:
Code:std::string mynumstr = "The number is: "; mynumstr += x; MessageBox(NULL, mynumstr.c_str(), "Msg", MB_OK);
Both, Why do you ask ?Because you made it sound as if MessageBox acted something like C sprintf and a VB string. Neither of those is correct and your suggestion was way off the mark.You need to add a comma before starting the argument list.
The string in C/C++ is "The number is:" - the x is ignored and that line will not compile. "Msg" is the title of the message box and MB_OK is the style. x has no meaning except maybe in a VB string where auto-concatenation works.MessageBox(NULL,"The number is: "x,"Msg",MB_OK);
Code:int x = 5; char text[32] sprintf(text,"The number is %d",x); MessageBox(0,text,"Msg",MB_OK);And I'm sure there are other ways as well. Use what works.Code:int x = 5; std::ostringstream ostrm; ostrm << "The number is " << x << std::endl; MessageBox(0,ostrm.str().c_str(),"Msg",MB_OK);
Last edited by VirtualAce; 08-02-2009 at 06:15 PM.
Ah, I see. But you do require a comma after each argument as far as the syntax goes right ? even though the above code is wrong.
for example, without the x it would be
Code:MessageBox(NULL,"The number is: ", "Msg" ,MB_OK);
Spidey out!
Yes but that does not give you the number since you passed in a string literal.
I think the question they meant to ask was "Spidey, how much Windows programming have you done?" (since I imagine there are C/C++ programmers who have gone their whole lives without using MessageBox).