views:

326

answers:

2

I always thought the output window for a MSVC++ app running in the debugger was mapped to one of the standard output streams. But When I run this code in a Windows MFC app, nothing is seen:

std::cerr << "cerr"<<std::endl;
std::cout << "cout"<<std::endl;
std::clog << "clog"<<std::endl;

Is this a Windows thing or a VC++ thing? How are functions/macros like TRACE and OutputDebugString writing to this window, and shouldn't I be able to do so without using them?

+1  A: 

There is no standard style stream mapped to the Visual Studio output window. The function that accomplishes this is OutputDebugString().

The closest thing you can get to something like this is create your own wrapper class that behaves like an ostream, and underneath calls OutputDebugStream.

Ramon Zarazua
Does OutputDebugStream, as the name suggests, only function when _DEBUG is defined? If so, it's not much use for debugging release-mode-with-debug-info .exes... neither is TRACE for that matter.
John
OutputDebugString is a Windows API function and so available in both debug and release builds. Typically macros like TRACE are debug only, so you'll want to explicitly call OutputDebugString if you wish to continue writing the messages in a release build.
Stephen Nutt
Cool, thanks for the clarification
John
You can further customize this by enabling or disabling this sort of calls yourself in a custom wrapper http://stackoverflow.com/questions/1389538/cancelling-stdcout-code-lines-using-preprocessor/1389813#1389813
Ramon Zarazua