17.3 Files and streams °当打开一个文件时,该文件就和某个流关联起 来了。对文件进行读写实际上受到一个文件定 位指针( file position pointer)的控制。 ●输入流的指针也称为读指针,每一次提取操作 将从读指针当前所指位置开始,每次提取操作 自动将读指针向文件尾移动。 输出流指针也称写指针,每一次插入操作将从 写指针当前位置开始,每次插入操作自动将写 指针向文件尾移动。 0 2018, SEU. All rights reserved. 11
© 2009, SEU. All rights reserved. © 2018, SEU. All rights reserved. 11 17.3 Files and Streams 当打开一个文件时,该文件就和某个流关联起 来了。对文件进行读写实际上受到一个文件定 位指针(file position pointer)的控制。 输入流的指针也称为读指针,每一次提取操作 将从读指针当前所指位置开始,每次提取操作 自动将读指针向文件尾移动。 输出流指针也称写指针,每一次插入操作将从 写指针当前位置开始,每次插入操作自动将写 指针向文件尾移动
17.3 Files and streams 1O流模板之间的继承关系 basic ios basic istream basic ostream basic ifstream basic iostream basic ofstream basic fstream 为了在C++中执行文件处理,必须包含头文件 <iostream>FA<fstream> 0 2018, SEU. All rights reserved. 12
© 2009, SEU. All rights reserved. © 2018, SEU. All rights reserved. 12 17.3 Files and Streams -- I/O流模板之间的继承关系 为了在C++中执行文件处理,必须包含头文件 <iostream>和<fstream>
173 Files and streams-文件处理 °必须包含头文件: o #include <fstream> o <fstream> °包括三种类模板的定义 o basic_ifstream(for file input) o basic_ofstream(for file output o basic_fstream (for file input and output) ●提供了处理字符流的模板特化 ° ifstream:从文件中读入字符(读文件) ° ofstream:向文件输出字符(写文件 fstream:支持文件中字符的输入和输出 生成这些流类模板特化的对象,即可打开文件 程序和文件之间通过流对象交互 0 2018, SEU. All rights reserved. 13
© 2009, SEU. All rights reserved. © 2018, SEU. All rights reserved. 13 17.3 Files and Streams --文件处理 必须包含头文件: #include <fstream> <fstream> 包括三种类模板的定义 basic_ifstream (for file input) basic_ofstream (for file output) basic_fstream (for file input and output) 提供了处理字符流的模板特化 ifstream:从文件中读入字符(读文件) ofstream:向文件输出字符(写文件) fstream:支持文件中字符的输入和输出 生成这些流类模板特化的对象,即可打开文件 程序和文件之间通过流对象交互
Topics o 17.1 Introduction o 17.2 The Data Hierarchy 17.3 Files and streams o 17.4 Creating a Sequential File o 17.5 Reading Data from a Sequential File o 17. 6 Input/Output of objects 0 2018, SEU. All rights reserved. 14
© 2009, SEU. All rights reserved. © 2018, SEU. All rights reserved. 14 Topics 17.1 Introduction 17.2 The Data Hierarchy 17.3 Files and Streams 17.4 Creating a Sequential File 17.5 Reading Data from a Sequential File 17.6 Input/Output of Objects