Sor*_*tis 78
OutputDebugString函数会做到这一点.
示例代码
void CClass::Output(const char* szFormat, ...)
{
char szBuff[1024];
va_list arg;
va_start(arg, szFormat);
_vsnprintf(szBuff, sizeof(szBuff), szFormat, arg);
va_end(arg);
OutputDebugString(szBuff);
}
Run Code Online (Sandbox Code Playgroud)
小智 72
如果这是用于调试输出,那么OutputDebugString就是你想要的.一个有用的宏:
#define DBOUT( s ) \
{ \
std::ostringstream os_; \
os_ << s; \
OutputDebugString( os_.str().c_str() ); \
}
Run Code Online (Sandbox Code Playgroud)
这允许你说:
DBOUT( "The value of x is " << x );
Run Code Online (Sandbox Code Playgroud)
您可以使用__LINE__和__FILE__宏扩展它以提供更多信息.
对于那些在Windows和广泛的土地:
#include <Windows.h>
#include <iostream>
#include <sstream>
#define DBOUT( s ) \
{ \
std::wostringstream os_; \
os_ << s; \
OutputDebugStringW( os_.str().c_str() ); \
}
Run Code Online (Sandbox Code Playgroud)
Reu*_*nen 19
使用OutputDebugString功能或TRACE宏(MFC),您可以进行printf格式化:
int x = 1;
int y = 16;
float z = 32.0;
TRACE( "This is a TRACE statement\n" );
TRACE( "The value of x is %d\n", x );
TRACE( "x = %d and y = %d\n", x, y );
TRACE( "x = %d and y = %x and z = %f\n", x, y, z );
Run Code Online (Sandbox Code Playgroud)