C ++ learning 14th-I/O Stream

Source: Internet
Author: User

1. I/O Stream

I/O functions are not part of the C ++ language; they come from the C ++ standard library iostream;

1) iostream Library:


2) stream

In C ++, I/O processing is a stream. A stream is a finite ordered byte, also known as a buffer pool.

There are two main types of stream: input stream and output stream.

3) Input and Output in C ++

IOS is the most common input and output base class; istream and ostream process the original class of input and output;

4) Standard stream in C ++

Mainly include: Cin, cout, cerr and clog

CIN is mainly for keyboard input, and the last three are mainly for display output.

Cerr is a non-buffered output that can process data types. Clog is a buffer type and Outputs Data in blocks.


2. input stream

Iostream is a very complex library. The most common section is discussed here.

All I/O functions are in the STD namespace;

1) extract Operators

> It is the input extraction operator. Generally, it processes built-in data types. You can reload it to process custom data types.

2) extraction and blank symbols

You can enter a single character through>, but the blank space is ignored. You can use cin. Get (CH) to write down the blank space;

You can also use cin. Get (BUF, length) to obtain the input of the specified length;

You can also use cin. Getline (BUF, length) to obtain the input of the specified length;

Input that is applied to string: Getline (CIN, STR ).

Some useful istream functions:

Ignore (), discard the first character in the stream; ignore (INT count), discard the first count character in the stream;

Peek (): reads a character from the stream, but does not remove it from the stream; upget () returns the character retrieved last time; putback (char ch) puts a character back.

To be continued ......

[Disclaimer:
1) This content may come from the Internet, or I have sorted it out by myself. It only represents the opinions and opinions of the Internet and individuals!
2) This content is for reference only. Any reference to this content will cause any consequences and will be irrelevant to the original author and the author of this blog !]

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.