Display an int in a MessageBox?
-
Wednesday, August 31, 2005 2:37 PMHi,
I'm new to C++, have started to use VC++ 2003 at work and dont know much about it because i have only used Java and VB before now. I cant use the debugger for reasons that arent relevant here but all i want to do is use a MessageBox to display an int! I cant seem to do this no matter what i try. I dont care if i have to use the AfxMessageBox function instead but please some one tell me how its done! I'll give you the example below
int back_color = 2;
how do i display that 2 or rather back_color in a messagebox? thats all i am asking!
Many thanks
Will
All Replies
-
Wednesday, August 31, 2005 4:27 PM
Hi Will,
You have to pass a string to the MessageBox APIs. Here's an example of how to get a string to display the int value in VS 2005 (if you're using 2003, just remove the "L" in front of the first argument to s.Format):
CString s;
s.Format(L"%d",1);
AfxMessageBox(s);
Hope this helps,
-Ron Pihlgren
VC++ Testing -
Thursday, September 01, 2005 8:48 AM
Thanks, although i am using 2003 and i had to keep the 'L' in, so i take it FORMAT is a method in the CString class?
Thanks again
Will -
Thursday, September 01, 2005 10:32 PMYes, format is a method in the CString class.
The "L" is needed if you are building for Unicode. I just mentioned it since the default for VS2003 was ANSI and the default for VS2005 is Unicode. You can change the defaults on either platform.
I'm glad this helped.
-Ron

