What is the difference between cerr and clog streams in c++?

C++Object Oriented ProgrammingProgramming

cerr and clog are both objects of the stderr stream. Following are the differences between them. You can also read about the cout object to get a clearer picture.

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 therefore it's used when we need to display the error message instantly. It doesn't 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.

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 (<<).

Updated on 30-Jul-2019 22:30:21