Click here to Skip to main content
12,823,663 members (52,300 online)
Click here to Skip to main content
Add your own
alternative version


18 bookmarked
Posted 5 Oct 2000

cout for MFC/Windows/Non Console applications

, 5 Oct 2000
Rate this:
Please Sign up or sign in to vote.
A trace macro which traces to a new console of the Windows application.
<!-- Add the rest of your HTML here -->


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 your 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(a == b);

And the output would be:

GetCurrentThreadId() = 1234
a == b = 0
szName = Dhananjay Gune

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.


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


About the Author

Dhananjay Gune
Architect Home Depot
United States United States
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralMy vote of 1 Pin
Laurent Cozic17-Jun-12 17:43
memberLaurent Cozic17-Jun-12 17:43 
Generalit will be better if you use LPCTSTR instand of CString Pin
code_discuss22-Nov-07 20:36
membercode_discuss22-Nov-07 20:36 
GeneralMaking cout much more general Pin
Adi Shavit28-Dec-04 4:37
memberAdi Shavit28-Dec-04 4:37 
GeneralVery Cool and a suggection! Pin
Behzad Ebrahimi1-Aug-04 5:54
memberBehzad Ebrahimi1-Aug-04 5:54 
GeneralThank you Pin
cwilper10-Nov-03 21:57
membercwilper10-Nov-03 21:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170308.1 | Last Updated 6 Oct 2000
Article Copyright 2000 by Dhananjay Gune
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid