Advertisement

"cout" in window prog. (for debug)

Started by March 08, 2002 04:18 PM
7 comments, last by csxpcm 22 years, 11 months ago
Dear all, Does anyone know how to provide a quick output of a variable (for debugging) in a windows app. Normally i use cout << variable; to check stuff, but since im not using a console application this doesn''t work. I would like just a quick pop-up menu or something. Thanks in advance, - Pete
MessageBox(NULL, "MESSAGE HERE", "Title", MB_OK);

should do it... you''ll have to convert any numerical values to strings to use this though. Hope it helps!
Advertisement

hello,
sorry to bother you again, but how do I apply the command to change a float to a char? I''m trying to use CStr (change to string?) but with no success? could u tell me which library a suitable function is located in and what its called.
Thanks in advance
- Pete




float temp;
temp = gCamera.mPosition.getx();

// not sure what goes in here to change it!

MessageBox(NULL, temp, "Title", MB_OK);
For converting ints to strings there''s this function called "itoa", and I guess there are similar functions for floats etc... any help?
The sprintf() function works well for building a string to put in a message box.

Other debugging options that might work as well or even better for you are: using the debugger (if your app isn''t fullscreen), or logging to a file (especially useful if you want to output a lot of debug information).
Doh. Shoulda thought of that
Advertisement
Alternatively.. use logs.... where you would normally have it printed to the screen, just write it to a log.

It's really simple too. Of course you have to check it after you've stopped running your program, so its not in-game (for that I'd just write any debug information to the screen).

Just thought I'd throw a few other options at you.

EDIT: didnt see that rhino had already suggested logs.. they're a great way of debugging, any failures at any point (failure to allocate memory, create display lists, set up rendering context, e.t.c... can all be output there).

Edited by - Cobra on March 9, 2002 9:36:52 AM
"Build a man a fire, and he will be warm for a day. Set a man on fire, and he will have warmth for the rest of his life"
To save your self a whole LOT of time you can make a MessageBox function, Sounds HArd but is so simple

void MsgBox(char* message, ...)
{
MessageBox(NULL, message, "Appname", MB_OK);
}

Then you can use it just like the cout function (sorta)


Just type

int int1;
int 1 = 40;
MsgBox("Integer 1 is: %i", Int1);


Output:

A message box saying:

Integer 1 is: 40

----- ShCiPwA -----
----- ShCiPwA -----
To save your self a whole LOT of time you can make a MessageBox function, Sounds HArd but is so simple

void MsgBox(char* message, ...)
{
MessageBox(NULL, message, "Appname", MB_OK);
}

Then you can use it just like the cout function (sorta)


Just type

int int1;
int 1 = 40;
MsgBox("Integer 1 is: %i", Int1);


Output:

A message box saying:

Integer 1 is: 40

----- ShCiPwA -----
----- ShCiPwA -----

This topic is closed to new replies.

Advertisement