How to show a number...

Hi again (yes, I am new to programming),
How can I show a number that is in a variable in the MessageBox?  There is no "%d" like with printf, hence the question.

Thanx.
lamaAsked:
Who is Participating?
 
thresher_sharkConnect With a Mentor Commented:
Answer coming...
0
 
thresher_sharkCommented:
To do this, you want to create a temporary CString object.  Then, you can use the "Format" member function to create a string with the value of a variable.  Here is an example:

int var_you_want_shown = 123; // This is the variable you want to display.
CString temp;                 // This is only a temporary buffer.
temp.Format ("The value of var_you_want_shown is %d", var_you_want_shown); // This is similar to "printf"
MessageBox (temp, "Here it is!"); // This is the message box function displaying the temporary string.

Note that this technique can be applied to essentially any data type.  You can use the familiar "%d" "%ld" "%s" and "%f" format strings.  You might consider looking the functions up in the help because it explains all of the format strings.

If you have further questions, please feel free to ask.  Thanks!
0
 
lamaAuthor Commented:
Good, that fixed my problems too.  I am so new at MFC... I don't know anything! 8-)
0
 
The_BrainCommented:
this is my way sweet and straight to the answer. :)
char buffer[5];
Messagebox(0, _iota(number, buffer, 10)

_itoa(NUMBER, *buffer/buffer[](which is a pointer), radix/BASE)

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.