Click here to Skip to main content
13,558,538 members
Click here to Skip to main content
Add your own
alternative version


19 bookmarked
Posted 16 Apr 2003
Licenced CPOL

Double-click on the trace message in the Output window in Developer Studio to get to the line of code

, 14 Oct 2005
Rate this:
Please Sign up or sign in to vote.
Take advantadge of the output window in Developer Studio.


In some instances, you may find it advantageous to format your debug dump like:

filepathname.cpp(123) : something

When such a line is displayed in the Output window of your Developer Studio/Visual Studio, you can double-click on it, and jump to the location specified by the file path/line number pattern. It is very handy to generate debug dumps with easy access to the original line, so I wrote a macro to format debug dumps with the __FILE__ and __LINE__ preprocessors.

I first found this feature of the build output window in the Knowledge Base article HOWTO: Use #pragma to Generate User-Defined Warning Messages, which is almost ideal to insert TODO blocks. Later I tried it in the debug output, and found it also existed in the debug output window. It may work in other output windows too.

More Information

The following code illustrates how to tell the compiler to format the debug dump with file path and line numbers:

// collisions.h
#ifdef _DEBUG
#define TRACE_LINE(string) \
  CString  strTrace;           \
  strTrace.Format("%s(%d) :  \t%ld:\t%s",  \
    __FILE__,__LINE__,timeGetTime(),string);       \
  if (strTrace.GetLength() > 512) \
    TRACE("TRACE string too long !\r\n"); \
  else TRACE(strTrace);}
#define TRACE_LINE(string)              void(0)

// collisions.cpp
TRACE_LINE("Need to do 3D collision testing") ;

Debug output:

collisions.cpp.cpp(123) : Need to do 3D collision testing

I have other varieties of this such as TRACE_LINE1 which takes a format string and a parameter, and TRACE_LINE2 which takes a format string and two parameters, and so on. You can surely write yourself one without the MFC support also.

For additional information concerning the __FILE__ and __LINE__ predefined macros, see the Visual C++ Help file; Search on: "predefined macros", Topic: "Preprocessor Reference", and click on "ANSI".


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Sheng Jiang 蒋晟
United States United States
JIANG,Sheng, a Microsoft Most Valuable Professional in Visual C++ since 2004, is a student at Austin Community College. He is active in Visual C++ forums, blogs and newsgroups, such as CSDN, Netease, Joycode and Microsoft forums and newsgroups. He prefer plays computer games (espacially RTS ones) in his spare time.

You may also be interested in...


Comments and Discussions

GeneralVisual Studio's "Task List" or "Error List" Pin
JesseChisholm1-May-09 8:00
memberJesseChisholm1-May-09 8:00 
GeneralWon't work for UNICODE Pin
yafan17-Oct-05 11:15
memberyafan17-Oct-05 11:15 
GeneralRe: Won't work for UNICODE Pin
JesseChisholm1-May-09 7:54
memberJesseChisholm1-May-09 7:54 
GeneralCompile error Pin
vulcy30-May-05 22:16
membervulcy30-May-05 22:16 
Generalgood article Pin
kingzai21-Apr-03 20:33
memberkingzai21-Apr-03 20:33 

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.180515.1 | Last Updated 14 Oct 2005
Article Copyright 2003 by Sheng Jiang 蒋晟
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid