I have not used this, but boost filtering_stream may help.
As an example, I found a mailing list with indent.hpp that implements an output filter that outputs indentation:
boost::iostreams::filtering_ostream out;
indent_filter::push(out,2);
out.push(std::cout);
And use it like this:
out << "Hello Filter!\n"
<< indent_in
<< "this is\n"
<< "indented\n"
<< indent_out
<< "until here\n"
;
:
Hello Filter!
this is
indented
until here