Skip to content

Instantly share code, notes, and snippets.

@iondune
Created March 15, 2018 22:18
Show Gist options
  • Save iondune/1afeee9307717c0af8d286c889502c6f to your computer and use it in GitHub Desktop.
Save iondune/1afeee9307717c0af8d286c889502c6f to your computer and use it in GitHub Desktop.
Write messages from cout to Visual Studio debug output window
// https://stackoverflow.com/a/47312126/1390945
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;
std::cout.rdbuf(&g_DebugStreamFor_cout); // Redirect std::cout to OutputDebugString!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment