Post by Alberto Ganesh BarbatiPost by VectorI guess u meant unbuffered instead of unitbuffered......
No, the OP really meant unitbuffered. He is referring to the
fact that cerr has the flag "unitbuf" set.
Post by Vectorcerr is like cout. It is basically an error stream that is
attached to the console.You could have used cout there but
the advantage with cerr is that it can be re-routed to a
logfile and cout only points to the console screen.
This is inaccurate. First of all cerr is unitbuffered, while
cout is not, so they *are* different. Secondly, even cout can
be re-routed, by calling the C function freopen on stdout.
More to the point, where they go depends on the system and
context; I write server software, which runs deconnected from
any terminal, and typically, both cout and cerr are connected to
/dev/null; in cron jobs, they end up being mailed to the user. I
don't know were cout and cerr go in a Windows program (or GUI
programs under Unix), but there generally isn't an associated
terminal there either to which they can be sent.
Secondly, of course, freopen doesn't affect cout and cerr. You
can reroute them by using the non-const basic_ios<>::rdbuf(),
but typically, it is easier to just open a new file.
Most of the time, rerouting is done by the system, before the
program is actually started -- both the Windows shell and all of
the Unix shells use "> file" in the command line to reroute cout
to "file"; the Unix shells I use (ksh and bash) allow "2> file"
to reroute cerr, but I don't know if this is possible in the
Windows shell, and I don't think it is possible in Unix shells
based on the csh. In fact, for programs invoked from the command
line, it is fairly rare for cerr to be redirected, even in
shells where it is possible, where as redirecting cout is rather
common.
--
James Kanze GABI Software
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]