What are the differences between cout, cerr, and clog?

Source: Internet
Author: User


  • Windows + vs: In the console, cout can be redirected to files, and cerr and clog cannot. Redirecting an output to a file is actually an output stream connected to one pipe and an input file stream connected to the other.

  • Cout has its own buffer zone. When the buffer zone is full or the Endl is used, the terminal is refreshed (the screen is used by default). If the cerr has no buffer zone, the terminal is refreshed directly.

  • Cout write cache operations and system refresh terminal operations are asynchronous, so when the program crashes, the content that should be output in the code execution order may be only a part of the output, instead of all output, because the program has crashed.

  • Cout and printf are actually writing cache. This causes a problem. When the buffer is full and is not consumed, cout and printf will be blocked. For example, when program a redirects cout to program B through the pipeline, if the buffer is full, but program B never consumes the buffer, then the cout in program a will block until it knows that program B consumes the buffer.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.