trace.h
/*
* 需要设置:
*(1): 项目属性->C/C++-> Preprocessor-> Preprocessor Definitions->_DEBUG
*(2): 菜单-> Project-> Proprties-> General-> Character Set -> not set
*/
#include <windows.h>
#ifdef _DEBUG
bool _trace(const char *format, ...);
#define TRACE _trace
#else
#define TRACE false && _trace
#endif
trace.cpp
#ifdef _DEBUG
#include "trace.h"
bool _trace(const char *format, ...)
{
TCHAR buffer[1000];
va_list argptr;
va_start(argptr, format);
wvsprintf(buffer, format, argptr);
va_end(argptr);
OutputDebugString(buffer);
return true;
}
#endif
main.cpp
#include "trace/trace.h"
#include <windows.h>
int main() {
const char *str = "test to print the string\n";
TRACE("%s", str);
int i = 0;
return 0;
}