How to write to the Output window in Visual Studio?

前端 未结 7 2031
小鲜肉
小鲜肉 2021-01-30 02:39

Which function should I use to output text to the \"Output\" window in Visual Studio?

I tried printf() but it doesn\'t show up.

7条回答
  •  后悔当初
    2021-01-30 03:32

    If this is for debug output then OutputDebugString is what you want. A useful macro :

    #define DBOUT( s )            \
    {                             \
       std::ostringstream os_;    \
       os_ << s;                   \
       OutputDebugString( os_.str().c_str() );  \
    }
    

    This allows you to say things like:

    DBOUT( "The value of x is " << x );
    

    You can extend this using the __LINE__ and __FILE__ macros to give even more information.

    For those in Windows and wide character land:

    #include 
    #include 
    #include 
    
     #define DBOUT( s )            \
    {                             \
       std::wostringstream os_;    \
       os_ << s;                   \
       OutputDebugStringW( os_.str().c_str() );  \
    }
    

提交回复
热议问题