0

As I describled,I want to use the macro TRACE in conventional chracter-mode programming.
When I try directly using the command TRACE(...),I encounted a mistake tips which says that TRACE ,identifier not found.

So,what should I do to solve this problem?
3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by vijayan121
0

So,what should I do to solve this problem?

Write your own TRACE().

#include <cstdarg>
#include <cstdio>
#include <windows.h>
#include <iostream>

void TRACE( const char* format, ... )
{
    va_list args ;
    va_start( args, format ) ;

    enum { MAX_MESSAGE_SIZE = 4192 } ;
    char msg[ MAX_MESSAGE_SIZE ] ;
    std::vsnprintf( msg, MAX_MESSAGE_SIZE, format, args ) ;

    va_end(args) ;

    if( ::IsDebuggerPresent() ) ::OutputDebugStringA(msg) ;
    else std::clog << "DEBUG => " << msg ;
}

int main()
{
    TRACE( "test: (%+8.*d) <%#.3X> {%#6.3f} [%6.*s]\n", 4, 10, 200, 1.0, 4, "abcdef" ) ;
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.