Created
March 15, 2018 22:18
-
-
Save iondune/1afeee9307717c0af8d286c889502c6f to your computer and use it in GitHub Desktop.
Write messages from cout to Visual Studio debug output window
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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