$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: Brian Braatz (brianb_at_[hidden])
Date: 2005-02-27 14:56:51
However, I am NOT (yet) an expert in the Iostreams library so please
excuse me if I am missing something obvious.
I add 2 sinks
filtering_ostream out;
out.push(file_sink("Report.txt"));
out.push(cout);
I get an exception thrown on the second one (regardless of which one
goes in first)
In searching the archives, I noticed this mail:
where Johnathon Turkis writes:
"For this we need to define an OutputFilter which stores a reference to
an ostream and has a member function 'write' which forwards all
characters to the stored ostream as well as to the downstream sink
(you don't need to understand the following code -- the point is that
it's just a few lines):
struct tee : boost::io::output_filter {
tee(std::ostream& dest) : dest(dest) { }
template<typename Sink>
void write(Sink& snk, char* s, std::streamsize n)
{
// Write to the downstream Sink
boost::io::write(snk, s, n);
// Write to the stored ostream:
dest.write(s, n);
}
std::ostream& dest;
};
We use the tee as follows. Given two ostreams
ostream first;
ostream second;
we define a filtering_ostream which passes data through the tee to
both streams:
filtering_ostream out;
out.push(tee(first));
out.push(second);
out << "this gets written to both ostreams\n";
"
Which looks "good" except I suspect the library has changed since the
above is not compiling for me under VC71. (it complains about wanting a
Put() instead of a write())..
Any help appreciated- and also - a request- if "tee" functionality could
be officially implemented in the streaming lib for output sinks.
OR if it already is, I request that how do to it be spelled out more
clearly in the documentation.
Thanks
Brian Braatz