I want to use this snippet from Mr-Edd\'s iostreams article to print std::clog somewhere.
#include
#include
#include
I encourage you to look at Boost.IOStreams. It seems to fit your use-case nicely, and using it is surprisingly simple:
#include
#include
#include
namespace bio = boost::iostreams;
class MySink : public bio::sink
{
public:
std::streamsize write(const char* s, std::streamsize n)
{
//Do whatever you want with s
//...
return n;
}
};
int main()
{
bio::stream_buffer sb;
sb.open(MySink());
std::streambuf * oldbuf = std::clog.rdbuf(&sb);
std::clog << "hello, world" << std::endl;
std::clog.rdbuf(oldbuf);
return 0;
}