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

后端 未结 7 1533
小蘑菇
小蘑菇 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:42

    Standard output stream (cout): cout is the instance of the ostream class. cout is used to produce output on the standard output device which is usually the display screen. The data needed to be displayed on the screen is inserted in the standard output stream (cout) using the insertion operator (<<).

    Un-buffered standard error stream (cerr): cerr is the standard error stream which is used to output the errors. This is also an instance of the ostream class. As cerr is un-buffered so it is used when we need to display the error message immediately. It does not have any buffer to store the error message and display later.

    Buffered standard error stream (clog): This is also an instance of ostream class and used to display errors but unlike cerr the error is first inserted into a buffer and is stored in the buffer until it is not fully filled.

    further reading : basic-input-output-c

提交回复
热议问题