Sahba
Sahba

Reputation: 11

I want to know how and where can I use "cerr" in c++?

I want to know how and where can I use "cerr" in c++?

Upvotes: 1

Views: 333

Answers (3)

maditya
maditya

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 coutstatements to debug a program that already has a lot of output, you can use cerrto print statements that denote that some error has occurred).

Upvotes: 0

poitroae
poitroae

Reputation: 21367

Everywhere you

  1. #include <iostream> and
  2. use the std:: namespace

Upvotes: 2

M. Suleiman
M. Suleiman

Reputation: 848

The conventional stream to send errors through. cerr.

Also, Shall I use cerr

Upvotes: 1

Related Questions