Reputation: 11
I want to know how and where can I use "cerr" in c++?
Upvotes: 1
Views: 333
Reputation: 8896
cerr
is used to pass strings to the error stream. It is different from cout, which is the output stream.
For example, you can do the following:
cerr << "Hello world!" << endl;
By default, this directed to the terminal in the same way that cout is. However, it is useful if you want to redirect your errors to a different place than your output. For example, you may want to run a program and log all unexpected events or errors in a separate file, so that the user only sees the output that is meant for the user.
Alternatively, you may want to see only the errors (e.g. instead of using cout
statements to debug a program that already has a lot of output, you can use cerr
to print statements that denote that some error has occurred).
Upvotes: 0
Reputation: 848
The conventional stream to send errors through. cerr.
Also, Shall I use cerr
Upvotes: 1