MotivationIn a program which involves several output streams, the developer often wants to have
the same content sent to two distinct streams.
This usually happens when log messages, which are typically sent to a file, need also appear on the user's console, when the
program's "verbosity" flag is on.
In short, we would like to have a "tee" stream which forwards its incoming content to two different output streams. For example, the following piece of code, should print the line "Zapp Branigan" to the standard output ( cout) as well as to a file ("futurama.txt"):
basic_ostream class template
offers no virtual functions which can be overriden.
Alternatively, class basic_streambuf (used by basic_ostream) can be customized thru subclassing/overriding, but
this is an inadequate approach:
The data that is passed to a basic_streambuf object contains only the raw text, exlcuding any
formatting manipulators (such as: std::endl, std::width, etc.) thus discarding an important service of the stream library.
The solution: class basic_TeeStream |