#include <Windows.h>
#include <ostream>
#include <sstream>
#include <string>
//using namespace std;
template < class CharT, class TraintT = std::char_traits<CharT> >
class basic_debugbuf : public std::basic_stringbuf <CharT, TraintT>
{
~basic_debugbuf()
{
sync();
}
protected:
int sync()
{
WriteDebugString(str().c_str());
str(std::basic_string<CharT>());
return 0;
}
void WriteDebugString(const CharT * msg) {}
};
template <>
void basic_debugbuf<char>::WriteDebugString(const char *msg)
{
::OutputDebugStringA(msg);
}
template<>
void basic_debugbuf<wchar_t>::WriteDebugString(const wchar_t *msg)
{
::OutputDebugStringW(msg);
}
template< class CharT, class TraistT = std::char_traits< CharT> >
class basic_debugostream : public std::basic_ostream < CharT, TraistT>
{
public:
basic_debugostream() : std::basic_ostream < CharT, TraistT> (new basic_debugbuf<CharT, TraistT> ()) {}
~basic_debugostream() { delete rdbuf(); }
};
typedef basic_debugostream<char> DebugStream;
typedef basic_debugostream<wchar_t> WDebugStream;
C++ 流重定向输出到调试
最新推荐文章于 2021-05-26 13:02:12 发布