I am new to boost::iostreams
so this might be trivial:
Assuming namespace io = boost::iostreams;
this works
io::fil
Wrapping std::cout
with boost::ref worked for me:
io::filtering_ostream out(DummyOutputFilter() | boost::ref(std::cout));
See note_1 in pipable docs for details.
That's not the way you pass the stream. You have to use push
:
out.push(std::cout);
For the sake of completeness, a simple "Sink wrapper" looks like this:
#include <boost/iostreams/concepts.hpp>
#include <boost/iostreams/pipeline.hpp>
template<typename Sink>
class sink_wrapper
: public boost::iostreams::device<boost::iostreams::output, typename Sink::char_type> {
public:
sink_wrapper(Sink & sink) : sink_(sink) {}
std::streamsize write(const char_type * s, std::streamsize n) {
sink_.write(s, n);
return n;
}
private:
sink_wrapper & operator=(const sink_wrapper &);
Sink & sink_;
};
BOOST_IOSTREAMS_PIPABLE(sink_wrapper, 1)
template<typename S> sink_wrapper<S> wrap_sink(S & s) { return sink_wrapper<S>(s); }
And can be used like this:
boost::iostreams::filtering_ostream out(filter | wrap_sink(std::cout));