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:
#include <iostream>
using namespace std;
int main()
{
cerr << "Welcome to GfG! :: cerr" ;
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
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
11 Jan, 2021
Like Article
Save Article