我应该使用哪个函数将文本输出到Visual Studio中的" output“窗口?
我尝试过printf()
,但没有显示出来。
发布于 2009-07-19 10:31:03
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);
}
发布于 2009-07-19 10:31:06
如果这是为了调试输出,那么OutputDebugString就是您想要的。一个有用的宏:
#define DBOUT( s ) \
{ \
std::ostringstream os_; \
os_ << s; \
OutputDebugString( os_.str().c_str() ); \
}
这样你就可以说出这样的话:
DBOUT( "The value of x is " << x );
您可以使用__LINE__
和__FILE__
宏对其进行扩展,以提供更多信息。
对于Windows和宽字符区域中的用户:
#include <Windows.h>
#include <iostream>
#include <sstream>
#define DBOUT( s ) \
{ \
std::wostringstream os_; \
os_ << s; \
OutputDebugStringW( os_.str().c_str() ); \
}
发布于 2009-07-19 10:32:31
使用OutputDebugString
函数或允许您进行printf
-style格式设置的MFC宏:
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 );
https://stackoverflow.com/questions/1149620
复制相似问题