Cout in C ++

Source: Internet
Author: User

In other words, we should all understand that this is implemented by reloading the operator <function.

Cout <123; cout <"ssss ";

But like

Cout <Endl;

How is it implemented?

At first, I guess Endl is a class or struct, and then implemented through a friend function.

But let's look at the implementation of STL. Originally, Endl is a function!

Template <typename _ chart, typename _ traits> inline basic_ostream <_ chart, _ traits> & Endl (basic_ostream <_ chart, _ traits> & _ OS) {return flush (_ OS. put (_ OS. widen ('\ n') ;}__ ostream_type & operator <(_ ostream_type & (* _ pF) (_ ostream_type &)) {return _ pF (* This );}

When cout <Endl is used, the flush function is called once.

From the followingCodeWe can also see one or two implementation principles.

Cout. Operator <(Endl );

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.