Try this:
#include<windows.h>
#include<iostream>
#define DebugMessage(str) OutputDebugString(str)
int main() {
DebugMessage("Hello");
std::cin.ignore();
return 0;
}
William Hemsworth
Posting Virtuoso
1,591 posts since Mar 2008
Reputation Points: 1,429
Solved Threads: 129
You are using a compiler with the world's best debugger. You don't need debug messages. Just compile your program for debug and use the debugger to set breakpoints, see the value of variables and program execution.
But to answer your question, how to print debug messages depends on whether you are writing a console program or a windows program. Console progrm: just using normal print() or cout statements wherever you want them. Windows programs are more difficult because it doesn't have a console window, so you have to use win32 api text output functions
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
I agree with AD on that, but there has been times when its been helpfull to use OutputDebugString to print directly to the output window, for example when I was working on a scheduler, every few minutes it would have display its status, which isn't possible to do using breakpoints. I suppose I could have also made a log file to do that but I found this way easier.
William Hemsworth
Posting Virtuoso
1,591 posts since Mar 2008
Reputation Points: 1,429
Solved Threads: 129
I never used OutputDebugString(). It appears to be sort of like assert(), where you can add debugging comments which don't show up when the program is compiled for release mode.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
It appears to be sort of like assert(), where you can add debugging comments which don't show up when the program is compiled for release mode.
OutputDebugString works the same regardless of release/debug build.
mitrmkar
Posting Virtuoso
1,809 posts since Nov 2007
Reputation Points: 1,105
Solved Threads: 395
Then why use it since you have to delete them all before releasing the program ?
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
Then why use it since you have to delete them all before releasing the program ?
Some wrapping around it is obviously needed, as for example MFC's TRACE macros.
mitrmkar
Posting Virtuoso
1,809 posts since Nov 2007
Reputation Points: 1,105
Solved Threads: 395
Oh I see -- that function is meant for MFC.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
Oh I see -- that function is meant for MFC.
No, it's rather a generic function for sending a string to a debugger.
mitrmkar
Posting Virtuoso
1,809 posts since Nov 2007
Reputation Points: 1,105
Solved Threads: 395