hello, what C++ functions should i use to output text to the "Output" window in Visual Studio?
i tried printf() but it doesnt show up.
thanks!
hello, what C++ functions should i use to output text to the "Output" window in Visual Studio?
i tried printf() but it doesnt show up.
thanks!
OutputDebugString function will do it.
example code
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);
}
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.
Use the OutputDebugString
function or the TRACE
macro (MFC) which lets you do printf
-style formatting:
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 );