#ifndef _DEBUGSTREAM_H #define _DEBUGSTREAM_H #include #include #include #include template > class basic_debugbuf : public std::basic_stringbuf { public: virtual ~basic_debugbuf() { sync(); } protected: int sync() { output_debug_string(str().c_str()); str(std::basic_string()); // Clear the string buffer return 0; } void output_debug_string(const CharT *text) {} }; template<> void basic_debugbuf::output_debug_string(const char *text) { ::OutputDebugStringA(text); } template<> void basic_debugbuf::output_debug_string(const wchar_t *text) { ::OutputDebugStringW(text); } template > class basic_dostream : public std::basic_ostream { public: basic_dostream() : std::basic_ostream(new basic_debugbuf()) {} ~basic_dostream() { delete rdbuf(); } }; typedef basic_dostream dostream; typedef basic_dostream wdostream; #endif // _DEBUGSTREAM_H