Study Notes of the iostream library in the C ++ standard library (I) Introduction to the iostream library and istream, ostream class, Cin, and cout object

Source: Internet
Author: User

C LanguageStdio. H is a function library instead of a class library.
Among them, scanf printf, which we use most often, is a number of independent global functions, because C language does not support classes.

The standard input/output library iostream of C ++ is a class library that is organized in the form of classes. To use the class in this library, you must first reference the namespace: Using namespace STD;
The most commonly used are CIN and cout, both of which are objects,CIN is the object of the istream class, And cout is the object of the ostream class.The input CIN> and the Left shift in the cout <and right shift> at the time of output are the operator overloading of the istream class and the ostream class respectively.

Three standard stream objects are created in the iostream Library:
1 CIN indicates the standard input istream object. Cin allows us to read data from the device.
2 cout indicates the ostream object of the standard output. cout allows us to write data to the device.
3. cerr indicates an ostream object with a standard error. cerr indicates an export.ProgramWhere an error message is sent, only data can be written to the screen device.

Standard streaming objects all have default devices:
Cout <data; the default device for cout is the display buffer.
Cin> data; the default device of CIN is the keyboard buffer.

The iostream library consists of fstream, iomainip, IOS, iosfwd, iostream, istream, ostream, sstream, streambuf, and strstream.
Istream is used to access the input stream of the operating system. ostream accesses the output stream of the operating system. iostream also inherits these two classes.

In the ostream class, many left shift operators are overloaded, and each basic data type is overloaded, such
& Ostream operator <(ostream & temp, int source );
& Ostream operator <(ostream & temp, char source );
& Ostream operator <(ostream & temp, char * Source );
Because the data types returned by the above overload are referenced by ostream, ostream can be used as the left value, so cout <"ABC" <Endl <123;

In the istream class, many right shift> operators are also overloaded, and each basic data type is overloaded, such
& Istream operator> (istream & temp, int source );
& Istream operator> (istream & temp, char source );

The above is the input and output of the standard input and output device of the terminal, that is, the input and output of the general PC keyboard and display.

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.