I tried researching the difference between cout
, cerr
and clog
on the internet but couldn't find a perfect answer. I still am not clear on when to use which. Can anyone explain to me, through simple programs and illustrate a perfect situation on when to use which one?
I visited this site which shows a small program on cerr
and clog
, but the output obtained over there can also be obtained using cout
. So, I'm confused over each one's exact use.
Generally you use std::cout
for normal output, std::cerr
for errors, and std::clog
for "logging" (which can mean whatever you want it to mean).
The major difference is that std::cerr
is not buffered like the other two.
In relation to the old C stdout
and stderr
, std::cout
corresponds to stdout
, while std::cerr
and std::clog
both corresponds to stderr
(except that std::clog
is buffered).