Non-MFC VC ++ project how to use TRACE macro

  If not, MFC or ATL project, then the project can not use this macro. At this time there is no additional consumption of a way to be able to do the debug output to the output window.

  In this project additionally includes windows.h header file, and then use OutputDebugString () function will be able to play with the TRACE () macro same effect. Carrying a little package and c it can be accepted in the same uncertain terms printf parameters.

The following program as an example.

#include <iostream>
#include <windows.h>
using namespace std;

bool _trace(TCHAR *format, ...)

{
    TCHAR buffer[1000];
    va_list argptr;
    va_start(argptr, format);
    wvsprintf(buffer, format, argptr);
    va_end(argptr);
    OutputDebugString(buffer);
    return true;

}



int main() {

    int test = 5;
    _trace("hi output:%d", test);
    int a;
    cin >> a;

}

 

Also remember to project properties General-> Character Set is set to Not Set or Multi Byte job with Unicode if not compile.

 

Guess you like

Origin www.cnblogs.com/jiangzhaowei/p/10705654.html
Recommended