What is the difference between cout, cerr, clog of iostream header in c++? When to use which one?

后端 未结 7 1528
小蘑菇
小蘑菇 2020-12-07 08:32

I tried researching the difference between cout, cerr and clog on the internet but couldn\'t find a perfect answer. I still am not cle

7条回答
  •  一整个雨季
    2020-12-07 08:40

    stdout and stderr are different streams, even though they both refer to console output by default. Redirecting (piping) one of them (e.g. program.exe >out.txt) would not affect the other.

    Generally, stdout should be used for actual program output, while all information and error messages should be printed to stderr, so that if the user redirects output to a file, information messages are still printed on the screen and not to the output file.

提交回复
热议问题