IO库是一个面向对象库,使用stream提供了输入输出功能。
什么叫stream呢?看这段叙述[1]:
A stream is an abstraction that represents a device on which input and ouput operations are performed. A stream can basically be represented as a source or destination of characters of indefinite length.
stream是一个设备的抽象。
stream一个物理的“字符源”和“字符目的地”关联,比如硬盘,键盘,控制台(console)。如果一个stream与一个设备关联,对此流的操作就会反映到相应的设备上。比如一个文件流(file stream),与文件交互,对此流的操作就会反应到相应的文件中。
C++的IO库主要有如下几个部分:
- Basic class templates
- Class template instantiations
有两种版本,一是如ios, istream, ofstream,对象是char,另一处是wios, wistream, wofstream,对象是wchar_t。
- Standard objects
<iostream>提供了些对象可以进行标准输入输出。如cin, cout, cerr, clog(char版本),wcin, wcout, wcerr, wclog(wchar_t版本)。如果我们执行如下代码:
cout << L"abc";
输出为:
输出的是字符常量的地址,而如果执行如下代码:
wcout << L"abc";
输出为:
输出正确。
- Types
- Manipulators
一、IO库类图
参考: