"Marc Schellens" <m_*********@hotmail.com> wrote in message
news:ck***********@news.riken.go.jp...
I want to create an object,
which replaces std::cout
all output will be put out to std::cout, but optional
also copied to a file.
But the file output needs to be manipulated:
every new line has to be preceded by a ';'
Is there an easy way to do so?
Or do I have to write wrappers for all kind of
<< operators?
And which functions to overload to scan for '\n'
likje ostr.put(...), any other (ie. are operator<<
using put(...) (always)?)
Look for "redirect cout" ...
What you need to do is replace the streambuf associated
with std::cout:
int main(void)
{
std:ostream * saveStream = cout.rdbuf();
MyStreamBuffer newBuf(.......);
cout.rdbuf(&newBuf);
try {
... the resto of te program ...
} catch(...) { error reporting... }
cout.rdbuf(saveStream); // restore cout to original state
}
To have output to both the console and a file, you should be
able to find a 'tee' stream buffer (I do not know a specific
implementation, but there are a few floating around on the web):
http://www.google.com/search?&q=Tee%20streambuf
hth -Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- e-mail contact form
Brainbench MVP for C++ <>
http://www.brainbench.com