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:
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.
- How to find Segmentation Error in C & C++ ? (Using GDB)
- erf | Error functions using cmath in C++
- NULL undeclared error in C/C++ and how to resolve it
- C++ Stream Classes Structure
- Overloading stream insertion (<>) operators in C++
- Object Slicing in C++
- Can a C++ class have an object of self type?
- Object Oriented Programming in C++
- Preventing Object Copy in C++ (3 Different Ways)
- Why C++ is partially Object Oriented Language?
- How to add reference of an object in Container Classes
- Exception handling and object destruction | Set 1
- Where is an object stored if it is created inside a block in C++?
- cin get() in C++ with Examples
- std::less in C++ with Examples
- Pi(π) in C++ with Examples
- ratio_equal() in C++ with examples
- std::bit_xor in C++ with Examples
- std::bit_or in C++ with Examples
- ios bad() function in C++ with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.