首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在Visual Studio中写入输出窗口?

如何在Visual Studio中写入输出窗口?
EN

Stack Overflow用户
提问于 2009-07-19 10:28:22
回答 6查看 154.3K关注 0票数 81

我应该使用哪个函数将文本输出到Visual Studio中的" output“窗口?

我尝试过printf(),但没有显示出来。

EN

回答 6

Stack Overflow用户

回答已采纳

发布于 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);
}
票数 89
EN

Stack Overflow用户

发布于 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() );  \
}
票数 74
EN

Stack Overflow用户

发布于 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 );
票数 21
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1149620

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档