[华工课件]C++程序设计基础第三版chap11-输入输出流

上传人:油条 文档编号:25650377 上传时间:2017-12-16 格式:PPT 页数:316 大小:3.33MB
返回 下载 相关 举报
[华工课件]C++程序设计基础第三版chap11-输入输出流_第1页
第1页 / 共316页
[华工课件]C++程序设计基础第三版chap11-输入输出流_第2页
第2页 / 共316页
[华工课件]C++程序设计基础第三版chap11-输入输出流_第3页
第3页 / 共316页
[华工课件]C++程序设计基础第三版chap11-输入输出流_第4页
第4页 / 共316页
[华工课件]C++程序设计基础第三版chap11-输入输出流_第5页
第5页 / 共316页
点击查看更多>>
资源描述

《[华工课件]C++程序设计基础第三版chap11-输入输出流》由会员分享,可在线阅读,更多相关《[华工课件]C++程序设计基础第三版chap11-输入输出流(316页珍藏版)》请在金锄头文库上搜索。

1、chap11 输入/输出流,I/O(输入/输出)流类库提供对象之间的数据交互服务 流类库预定义了一批流对象,连接常用的外部设备 程序员可以定义所需的I/O流对象,使用流库提供的工作方式 实现数据传输,第11章 输入/输出流,11.1 流类和流对象,11.2 标准流和流对象,11.3 格式控制,11.4 串流,11.5 文件处理,小结,程序中,对数据的输入/输出是以字节流实现的 应用程序对字节序列作出各种数据解释 I/O系统的任务就是在内存和外部设备之间稳定可靠地传输数据 和解释数据。 流类对象可以建立和删除,可以从流中获取数据和向流添加数据,11.1 流类和流对象,11.1.1 流类库,流库(

2、stream library)是用继承方法建立的输入输出类库 流库具有两个平行的基类:streambuf 和 ios 类,所有流类均以两者 之一作为基类 streambuf 类提供对缓冲区的低级操作设置缓冲区对缓冲区指针操作向缓冲区存/取字符 ios 类及其派生类提供用户使用流类的接口,支持对streambuf 的缓 冲区输入/输出的格式化或非格式化转换,streambuf,1. streambuf,对缓冲区的低级操作,11.1.1 流类库,streambuf,1. streambuf,对缓冲区的低级操作,11.1.1 流类库,文件缓冲区管理,streambuf,1. streambuf,对缓

3、冲区的低级操作,11.1.1 流类库,字符串缓冲区管理,streambuf,1. streambuf,对缓冲区的低级操作,11.1.1 流类库,标准I/O缓冲区管理,11.1.1 流类库,2. ios,提供用户接口,ios,iostream,11.1.1 流类库,2. ios,提供用户接口,ios,iostream,输入流,输出流,11.1.1 流类库,2. ios,提供用户接口,ios,iostream,输入流,输出流,输入文件流,输入串流,输出串流,输出文件流,11.1.1 流类库,2. ios,提供用户接口,ios,iostream,输入流,输出流,输入文件流,输入串流,输出串流,输出文

4、件流,输入/输出流,11.1.1 流类库,2. ios,提供用户接口,ios,iostream,输入流,输出流,输入文件流,输入串流,输出串流,输出文件流,输入/输出流,输入/输出文件流,输入/输出串流,标准输入/输出流,11.1.1 流类库,2. ios,提供用户接口,ios,iostream,输入流,输出流,输入文件流,输入串流,输出串流,输出文件流,输入/输出流,输入/输出文件流,输入/输出串流,标准输入/输出流,重载运算符“=”,重载运算符“=”,11.1.1 流类库,2. ios,提供用户接口,ios,iostream,输入流,输出流,输入文件流,输入串流,输出串流,输出文件流,输入

5、/输出流,输入/输出文件流,输入/输出串流,标准输入/输出流,重载运算符“=”,重载运算符“=”,11.1.2 头文件,iostream.h包含操作所有输入/输出流所需的基本信息含有cin、cout、cerr、clog对象,提供无格式和格式化的I/O iomanip.h包含格式化I/O操纵算子,用于指定数据输入输出的格式 fstream.h处理文件信息,包括建立文件,读/写文件的各种操作接口 每种C+版本还包含其他一些与I/O相关的库,提供特定系统的某些功能,标准流是C+预定义的对象,提供内存与外部设备进行数据交互功能 流的操作是流类的公有成员函数,11.2 标准流和流操作,11.2.1 标准

6、流,_内存_,istream cin,ostream cout,标准输入流,标准输出流,标准流为用户常用的外部设备提供与内存之间的通信通道,对数据进行解释和传输,提供必要数据缓冲,11.2.1 标准流,(1) cinistream 类的对象,通常连向键盘,可以重定向(2) coutostream 类的对象,通常连向显示器,可以重定向(3) cerrostream 类的对象,连向显示器。不能重定向(4) clogostream 类的对象,连向打印机。不能重定向,重定向操作见附录A2.4,istream类的公有成员函数,11.2.2 输入流操作,istream,istream类的公有成员函数,11

7、.2.2 输入流操作,11.2.2 输入流操作,int get();istream,istream类的公有成员函数,11.2.2 输入流操作,istream,istream类的公有成员函数,11.2.2 输入流操作,istream,istream类的公有成员函数,11.2.2 输入流操作,int peek();,istream类的公有成员函数,11.2.2 输入流操作,int gcount() const;,istream类的公有成员函数,11.2.2 输入流操作,void eatwhite();,istream类的公有成员函数,11.2.2 输入流操作,istream,istream类的公有

8、成员函数,11.2.2 输入流操作,streampos tellg();,long int,istream类的公有成员函数,istream类的公有成员函数,11.2.2 输入流操作,basic_istream,/ 例11-1 用get函数从键盘输入字符 #includeusing namespace std;int main() char c; cout Enter first sentence followed by Entern ; while ( (c = cin.get() != n ) cout.put(c); cout endl ; cout Enter second senten

9、ce followed by Entern ; while ( cin.get(c) ) if ( c=n ) break; cout.put(c); cout endl ; cout Enter third sentence followed by Entern ; char s 80 ; cin.get ( s, 10 ) ; cout s endl ;,11.2.2 输入流操作,/ 例11-1 用get函数从键盘输入字符 #includeusing namespace std;int main() char c; cout Enter first sentence followed by

10、 Entern ; while ( (c = cin.get() != n ) cout.put(c); cout endl ; cout Enter second sentence followed by Entern ; while ( cin.get(c) ) if ( c=n ) break; cout.put(c); cout endl ; cout Enter third sentence followed by Entern ; char s 80 ; cin.get ( s, 10 ) ; cout s endl ;,11.2.2 输入流操作,输入,/ 例11-1 用get函数

11、从键盘输入字符 #includeusing namespace std;int main() char c; cout Enter first sentence followed by Entern ; while ( (c = cin.get() != n ) cout.put(c); cout endl ; cout Enter second sentence followed by Entern ; while ( cin.get(c) ) if ( c=n ) break; cout.put(c); cout endl ; cout Enter third sentence follo

12、wed by Entern ; char s 80 ; cin.get ( s, 10 ) ; cout s endl ;,11.2.2 输入流操作,输出,/ 例11-1 用get函数从键盘输入字符 #includeusing namespace std;int main() char c; cout Enter first sentence followed by Entern ; while ( (c = cin.get() != n ) cout.put(c); cout endl ; cout Enter second sentence followed by Entern ; whi

13、le ( cin.get(c) ) if ( c=n ) break; cout.put(c); cout endl ; cout Enter third sentence followed by Entern ; char s 80 ; cin.get ( s, 10 ) ; cout s endl ;,11.2.2 输入流操作,/ 例11-1 用get函数从键盘输入字符 #includeusing namespace std;int main() char c; cout Enter first sentence followed by Entern ; while ( (c = cin.

14、get() != n ) cout.put(c); cout endl ; cout Enter second sentence followed by Entern ; while ( cin.get(c) ) if ( c=n ) break; cout.put(c); cout endl ; cout Enter third sentence followed by Entern ; char s 80 ; cin.get ( s, 10 ) ; cout s endl ;,11.2.2 输入流操作,指定输入字符数,/ 例11-1 用get函数从键盘输入字符 #includeusing

15、namespace std;int main() char c; cout Enter first sentence followed by Entern ; while ( (c = cin.get() != n ) cout.put(c); cout endl ; cout Enter second sentence followed by Entern ; while ( cin.get(c) ) if ( c=n ) break; cout.put(c); cout endl ; cout Enter third sentence followed by Entern ; char s 80 ; cin.get ( s, 10 ) ; cout s endl ;,

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 机械/制造/汽车 > 综合/其它

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号