简体   繁体   中英

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

我想知道如何以及在哪里可以在c ++中使用“cerr”?

Everywhere you

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

The conventional stream to send errors through. cerr .

Also, Shall I use cerr

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM