D
Dylan
What advantages does std::cerr offer over std::cout?
(I'm trying to understand why it exists)
thanks
(I'm trying to understand why it exists)
thanks
Dylan said:What advantages does std::cerr offer over std::cout?
(I'm trying to understand why it exists)
There is no "advantage".
It is frequently convenient to be able to separate "normal" from "abnormal" output. Thus one common use of cerr is to
log errors: i.e. one might (re)direct output to stderr (but not to stdout) to an error log, which might be a file, a
terminal screen or (my preferred option) a tannoy that squawks "ERROR! ERROR! ILLEGAL MEMORY ACCESS AT 0x038af2e2!
MISSION ABORT!".
Dylan said:hehe. So how do I redirect the output of std::cerr, say, to a file?
[email protected] said:| What advantages does std::cerr offer over std::cout?
On my OS, a common thing to do is to make programs reading from cin and
writing to cout. If foo and bar are two such programs, and I wrote
foo < infile | bar > outfile
then foo would have cin connected to the file infile, and its cout
connected to bar's cin. Bar's cout would be connected to the file
outfile.
If any of there is an error, an error message written to cerr would
appear on the screen immediately.
Cerr is not buffered, though, so excessive usage might be ineffient. If
you rather want to write information to the screen, there is also a
buffered version called clog.
summary:
cin buffered, connected to stdin
cout buffered, connected to stdout
cerr unbuffered, connected to stderr
clog buffered, connected to stderr.
The answer is very OS and compiler implementation specific
Lionel said:There is no "advantage".
It is frequently convenient to be able to separate "normal" from "abnormal" output. Thus one common use of cerr is to
log errors: i.e. one might (re)direct output to stderr (but not to stdout) to an error log, which might be a file, a
terminal screen or (my preferred option) a tannoy that squawks "ERROR! ERROR! ILLEGAL MEMORY ACCESS AT 0x038af2e2!
MISSION ABORT!".
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.