TRACE
TRACE(exp)
Parameters
exp
Specifies a variable number of arguments that are used in exactly the same way that a variable number of arguments are used in the run-time function printf.
Remarks
Provides similar functionality to the printf function by sending a formatted string to a dump device such as a file or debug monitor. Like printf for C programs under MS-DOS, the TRACE macro is a convenient way to track the value of variables as your program executes. In the Debug environment, the TRACE macro output goes to afxDump. In the Release environment, it does nothing.
TRACE is limited to sending a total of 512 characters at a time. If you call TRACE with formatting commands, the total string length after the formatting commands have been expanded cannot be more than 512 characters, including the terminating NULL. Exceeding this limit causes an ASSERT.
Note This macro is available only in the debug version of MFC.
For more information, see in Visual C++ Programmer’s Guide.
Example
// example for TRACE
int i = 1;
char sz[] = "one";
TRACE( "Integer = %d, String = %s\n", i, sz );
// Output: 'Integer = 1, String = one'
// another example for TRACE
// Note that the TRACE() macro accepts a LPCTSTR for the format string
// parameter, while the other TRACEn() macros accept a LPCSTR.
// This means that you should use the _T() macro on formatting strings
// you supply if you want to build both _UNICODE and non-_UNICODE from
// the same source.
TRACE(_T("Hockey is best!\n"));
// remember to include <stdlib.h> to get rand() and its friends
int nCount = rand();
TRACE(_T("There are %d fans at this moment.\n"), nCount);
See Also TRACE0, TRACE1, TRACE2, TRACE3, AfxDump, afxTraceEnabled