Team LiB
Previous Section Next Section

Chapter Summary


C++ uses library classes to handle input and output:

C++ 使用标准库类处理输入和输出:

  • The iostream classes handle stream-oriented input and output

    iostream 类处理面向流的输入和输出。

  • The fstream classes handle IO to named files

    fstream 类处理已命名文件的 IO。

  • The stringstream classes do IO to in-memory strings

    stringstream 类处理内存中字符串的 IO。

All of these classes are related by inheritance. The input classes inherit from istream and the output classes from ostream. Thus, operations that can be performed on an istream object can also be performed on either an ifstream or an istringstream. Similarly for the output classes, which inherit from ostream.

所有的这些类都是通过继承相互关联的。输入类继承了 istream,而输出类则继承了 ostream。因此,可在 istream 对象上执行的操作同样适用于 ifstreamistringstream 对象。而继承 ostream 的输出类也是类似的。

Each IO object maintains a set of condition states that indicate whether IO can be done through this object. If an error is encounteredsuch as hitting end-of-file on an input streamthen the object's state will be such that no further input can be done until the error is rectified. The library provides a set of functions to set and test these states.

所有 IO 对象都有一组条件状态,用来指示是否可以通过该对象进行 IO 操作。如果出现了错误(例如遇到文件结束符)对象的状态将标志无法再进行输入,直到修正了错误为止。标准库提供了一组函数设置和检查这些状态。

Team LiB
Previous Section Next Section