It seems rather tedious to output to debug window. Where can I find cout
output if I am writing a non-console information ?
Like:
double
SOLUTION: This answer solves the question and allows you to redirect console output to the Visual Studio Output window. First we need a class that overrides the default cout string stream:
class dbg_stream_for_cout
: public std::stringbuf
{
public:
~dbg_stream_for_cout() { sync(); }
int sync()
{
::OutputDebugStringA(str().c_str());
str(std::string()); // Clear the string buffer
return 0;
}
};
dbg_stream_for_cout g_DebugStreamFor_cout;
Then, somewhere you want to "activate" writing to the VS output window:
std::cout.rdbuf(&g_DebugStreamFor_cout); // Redirect std::cout to OutputDebugString!