Eighth Chapter: IO Library

Source: Internet
Author: User

I. IO class

1. iostream defines the basic type of read-write stream, FStream defines the type of read-write named file, Sstream defines the type of read-write memory string object

2. The IO object cannot be copied, so the formal parameter or return type cannot be set to the stream type: usually by reference and by side reflow

3. Reading and writing an IO object will change its state, so the passed and returned references cannot be const.

4. You should always check if it is in good condition before using a stream

5, Management output buffer

    • By default, CIN and Cerr are associated to cout, so reading CIN or writing cerr will cause the cout buffer to be flushed
    • " hi! " << end;    // output Hi and a newline character, then flush the buffer " hi! " << flush;    // output Hi, flush buffer, no extra characters attached " hi! " << ends;    // output hi and a null character, flush buffer

Ii. file input and output

1. Ifstream reads data from a given file, Ofstream writes data to a given file, FStream can read and write to a given file

2. Open File: FStream fstrm (s, mode); Open file by mode mode

      inch    // Open in read mode  out    // Open The app by writing    // Locate to the end of file after each write operation /    // Open file immediately to end of file trunc    // truncate file binary    // Binary mode for IO
    • By default, files opened in out mode are truncated even if trunc is not specified
    • To best Moss must specify the app mode himself to append write (Ofstream::out | Ofstream::app)

Eighth Chapter: IO Library

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.