Introduction
Typically, when an MFC program is being debugged, macros like TRACE
or variants thereof are used. These traces appear in the output window of the debugger. To see the traces, you have to be debugging (i.e., F5 in MSDEV). If you are executing it, i.e., Ctrl-F5, you cannot see those traces. If you still have to trace it, you probably use message boxes and that's irritating. This tracer lets you create a console window for your windows application and traces everything on that window, hence the name cout
. Moreover, when you trace, you probably put some text about what you are testing. For example:
char szName[] = "Dhananjay Gune";
printf("Name = %s\n", szName);
And the output would be:
Name = Dhananjay Gune
"cout
" has the following features:
- It's a DEBUG/RELEASE macro
- It can trace in RELEASE build, too
- It is a nice shorthand
- It automatically traces the expression you want to trace
- This tracer is different
- It can trace only one expression at a time
For example:
char szName[] = "Dhananjay Gune";
int a = 0, b = 1;
cout(GetCurrentThreadId());
cout(a == b);
cout(szName);
cout("Done");
And the output would be:
GetCurrentThreadId() = 1234
a == b = 0
szName = Dhananjay Gune
Done
For applications which do not have consoles, you have to put the CreateConsole()
macro in your main/WinMain/InitInstance/CWinApp constructor
. You should also put DeleteConsole()
before your program exits. There is no need to do so, however, because the system will FreeConsole()
anyway when the program exits.
Another free function that comes along with this is getLastErrorText()
which is self explanatory and is partly taken from the MSDN.
License
This article has no explicit license attached to it, but may contain usage terms in the article text or the download files themselves. If in doubt, please contact the author via the discussion board below.
A list of licenses authors might use can be found here.