George B wrote:
When I redirect standard output, I would like to duplicate a few lines of
this output to the console. If I add duplicates of the desired source
statements, changing cout to cerr, it works fine, but I end up with
duplicated lines when the program is executed without redirection. Is there
a way to test cout to tell whether its output is being redirected?
Like,
cout << "This information is very important" << endl;
if (cout_is_redirected) {
cerr << "This information is very important" << endl;
}
Thanks,
George
My understanding is that there is no method or functionality
to determine if "cout" has been redirected. Some platforms
allow for it to be redirected, others don't.
Many programs will have a "default" output stream. The program
would assign this to point to cout. It could be changed to
point to another output stream, such as a file. This would be
how a conforming program could redirect output. Also, one
may be able to tell if the output has been redirected by
comparing the value of the pointer.
--
Thomas Matthews
C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq:
http://www.parashift.com/c++-faq-lite
C Faq:
http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library