std::cerr | Error Stream Object in C++ with Examples

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

Standard error stream (cerr): cerr is the standard error stream which is used to output the errors. It is an instance of the ostream class. As cerr stream is un-buffered so it is used when we need to display the error message immediately and does not store the error message to display later. The object of class ostream that represents the standard error stream oriented to narrow characters(of type char). It corresponds to the C stream stderr.
The “c” in cerr refers to “character” and ‘err’ means “error”, Hence cerr means “character error”. It is always a good practice to use cerr to display errors.

Below is the program to illustrate cerr:





// C++ program to illustrate std::cerr
#include <iostream>
using namespace std;
// Driver Code
int main()
    // This will print "Welcome to GfG"
    // in the error window
    cerr << "Welcome to GfG! :: cerr";
    // This will print "Welcome to GfG"
    // in the output window
    cout << "Welcome to GfG! :: cout";
    return 0;


In the above program the Output of Line 11 will display an error window as:
RunTime Error in CPP code:

Welcome to GfG! :: cerr

Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at to report any issue with the above content.