Display an int in a MessageBox?

Hi,

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


Answer this question

Display an int in a MessageBox?

  • Sridhar Paladugu

    Yes, 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

  • ssmile73

    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


  • tricky_richy

    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

  • Display an int in a MessageBox?