Printing Variables in Win32

This is a discussion on Printing Variables in Win32 within the Windows Programming forums, part of the Platform Specific Boards category; I know this sounds like a n00bish question, but I can't figure out how to print a variable in an ...

  1. #1
    Laguna
    Guest

    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
    Posts
    1,571
    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.

    Code:
    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
    NoOneHere
    Guest
    another way is u could use a string stream

    Code:
    #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? ";
    
    temp<<Vara<<Varb<<Varc<<ends;
    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, 05: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, 08:13 PM
  4. Win32 API Tutorials?
    By c++_n00b in forum C++ Programming
    Replies: 9
    Last Post: 05-09-2002, 04:51 PM
  5. Variables in win32
    By Tazar_Azar in forum Windows Programming
    Replies: 9
    Last Post: 04-14-2002, 11:32 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21