output to multiple streams

Is there a standard way to output to multiple streams at the same time? I would like to pass an ostream to a function, write output strings into that stream, and have them go to both cout and a file. I'd like something like this: void DoSomething(ostream& ros) { ros << "This goes should go to cout and to a file" << endl; } multi_stream ms; fstream f("out.txt"); ms.add(cout); ms.add(f); DoSomething(ms); Any suggestions? Is this supported by the iostream library? I took a brief look at iostream doc and without really absorbing it, it doesn't seem to directly support this functionality. Maybe I need to read more carefully. Thanks, Andy

On 11/27/06, Andrew Schweitzer
Is there a standard way to output to multiple streams at the same time?
You could probably use something similar to: namespace io = boost::iostreams; fstream f("out.txt"); io::tee_devicestd::ostream,std::fstream teedev(std::cout, f); io::stream< io::tee_devicestd::ostream,std::fstream > my_tee(teedev); DoSomething(my_tee);
participants (2)
-
Aaron Griffin
-
Andrew Schweitzer