Stream Class Library

Source: Internet
Author: User

10th. Input/output stream

The I/O (input/output) Stream class library provides data interaction services between objects.

The Stream Class library pre-defines a batch of stream objects to connect to common external devices.

Programmers can define the required I/O Stream objects and implement the data transfer using the workflow provided by the Stream class library.

10.1 Stream classes and Stream objects

10.2 flag Stream and Stream object

10.3 Format Control

10.4 Streaming

10.5 File Processing

Summary

10.1 Stream classes and Stream objects

In the program, the input/output of the data is implemented by byte stream.

The application makes various data interpretations of the byte sequence.

The task of the I/O system is to reliably transfer data and interpret data between memory and external devices.

Stream class objects can be created and deleted, and data can be fetched from the stream and added to the stream.

10.1.1 Stream Class Library

The stream library is an input-output class library built with the inheritance method.

The stream library has two parallel base classes: Streambuf and iOS classes, all of which are based on one of the two classes.

The Streambuf class provides low-level operations on buffers.

Sets the buffer-to-buffer pointer operation to the buffer memory/fetch character

The iOS class and its derived classes provide users with interfaces that use the stream class to support formatted or unformatted conversions of buffer input/output to streambuf.

10.2.1 Standard Flow

(1) Cin IStream class objects, usually connected to the keyboard, can be redirected.

(2) objects of the cout Ostream class, usually connected to the display, can be redirected.

(3) Cerr Ostream class object, even to the display, can not redirect.

(4) Clog objects of the Ostream class, even to the printer, cannot be redirected.

10.2 flag Stream and Stream object

10.3 Format Control

iOS provides a control format function that directly sets the glyph.

The iostream and Iomanip libraries also provide a batch of controls to simplify I/O formatting operations.

int width (int)

Returns the width of the field previously set to display data

Char Fill (char)

Set the fill character, set the width of the hour, the free position is filled with padding characters, and the default is a space. This function returns the previously set padding character

Std::cout.width (20);//Setting the width of the display

Std::cout.fill (' * ');//Fill character

1#include <iostream>2 3 voidMain ()4 {5Std::cout.width ( -);//set the width of the display6Std::cout.fill ('*');//Fill character7 8Std::cout <<"Hello World"<<Std::endl;9 TenSystem"Pause"); One}

10.4 Streaming

10.5 File Processing

Summary

Stream Class 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.