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?

use assert() instead of TRACE. Or create a console project that supports MFC.

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" ) ;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.