Is it possible to create ostream object, which outputs to multiple destinations?
Posted
by
fiktor
on Stack Overflow
See other posts from Stack Overflow
or by fiktor
Published on 2011-11-22T01:40:20Z
Indexed on
2011/11/22
1:51 UTC
Read the original article
Hit count: 169
In 0-th approximation I have a class
class MyClass{
public:
...
std::ostream & getOStream(){return f;}
private:
ofstream f;
...
};
Which is used sometimes in the following way:
MyClass myclass;
myclass.getOStream()<<some<<information<<printed<<here;
But now I want to change the class MyClass, so that information will be printed both to f and to std::out, i.e. I want the above line to be equivalent to
myclass.f<<some<<information<<printed<<here;
std::cout<<some<<information<<printed<<here;
I don't know any good way to do that. Do you? Is there any standard solution (for example in stl or in boost)?
P.S.
I tried to search on this, but it seems that I don't know good keywords. Words multiple
, output
, ostream
, C++
, boost
seem to be too general.
© Stack Overflow or respective owner