
27 Nov
2006
27 Nov
'06
4:32 p.m.
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