"Fraser Ross" <fraserATmembers.v21.co.unitedkingdom> wrote in message
news:41******@news.greennet.net...
My program outputs to cout and I want it to output to a LOG file as
well. Is there a simple way to do that?
I have submitted a library to boost, to be reviewed around the
beginning of September, which allows this to be done easily
struct splitter : boost::io::sink {
tee(std::ostream& first, std::ostream& second)
: first(first), second(second)
{ }
void write(const char* s, std::streamsize n)
{
first.write(s, n);
second.write(s, n);
}
std::ostream& first;
std::ostream& second;
};
int main()
{
std::ofstream log("log.txt");
boost::io::stream_facade<splitter> out;
out.open(splitter(log, std::cout));
out << "this goes to cout and to log\n";
}
The library is here:
http://tinyurl.com/3m6ur
Jonathan