Thread: Printing Variables in Win32

  1. #1

    Printing Variables in Win32

    I know this sounds like a n00bish question, but I can't figure out how to print a variable in an alert box. Can anyone here tell me how?

  2. #2
    Registered User
    Join Date
    Apr 2002
    Not a problem. A MessageBox takes a char* so you need to convert the integer into a string. Fortunately for us there is already a function for just that.

    char buffer[256] = { 0 };
    int iNum = 55;
    // Format buffer for output
    sprintf( buffer, "Value is %i", iNum );
    MessageBox( NULL, buffer, "Alert", NULL );
    You'll need to include <stdio.h> if you haven't already.

  3. #3
    another way is u could use a string stream

    #include <strstream>
    #include <string>
    using std::strstream;
    using std::ends;
    using std::string;
    stringstream Temp;
    LPCSTR eTemp;
    char Vara[]="The Magic Value IS: ";
    int Varb=21;
    char Varc[]=" OK? ";
    eTemp = temp.str();
    (sorry 4 the dogey variable names
    then just pass eTemp to watever sub/function u want and it will contain the string int whatever

    hope it helps

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Headers and Global Variables
    By ajoo in forum C++ Programming
    Replies: 1
    Last Post: 05-15-2004, 04:49 AM
  2. Replies: 6
    Last Post: 01-02-2004, 01:01 PM
  3. static variables
    By Luigi in forum C++ Programming
    Replies: 4
    Last Post: 04-24-2003, 07:13 PM
  4. Win32 API Tutorials?
    By c++_n00b in forum C++ Programming
    Replies: 9
    Last Post: 05-09-2002, 03:51 PM
  5. Variables in win32
    By Tazar_Azar in forum Windows Programming
    Replies: 9
    Last Post: 04-14-2002, 10:32 PM