- 1、本文档共69页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
* 文件的随机读写:文件打开以后,系统自动生成两个隐含的流指针:读指针和写指针。在输入文件流类中,有关读指针的函数如下: 移动读指针函数 istream istream::seekg streampos pos ; 该函数的功能是将输入文件的指针移动到pos指定的位置中。 文件的读写 * istream istream::seekg streamoff offset,seek_dir origin ; 其中,origin的类型seek_dir是一个枚举类型,有以下三种取值: ios::beg 表示指针的起始位置为文件头 ios::cur 表示指针的起始位置为当前位置 ios::end 表示指针的起始位置为文件尾 该函数的功能是从origin指定的开始位置起,将文件指针移动offset个字节数。 文件的读写 * 返回读指针当前指向的位置值 ? streampos istream::tellg ; 该函数的功能是确定文件指针的当前位置。 文件的读写 * 相应地,ostream类提供有关写指针的函数如下: 移动写指针函数 ostream ostream::seekp streampos pos ; ostream ostream::seekp streamoff offset,seek_dir origin ; 返回写指针当前指向的位置值 streampos ostream::tellp ; 函数参数的意义与读指针函数一样。 文件的读写 * 例8-17 文件的随机读写 int main fstream file exam.dat,ios::in|ios::out|ios::binary ; if !file cout exam.dat can’t open endl; abort ; for int i 0;i 15;i++ file.write char* i,sizeof int ; streampos pos file.tellp ; cout current byte number: pos endl; for i 15;i 45;i++ file.write char* i,sizeof int ; file.seekg pos ; file.read char* i,sizeof int ; cout The data stored is i endl; file.seekp 0,ios::beg ; for i 80;i 100;i++ file.write char* i,sizeof int ; file.seekg pos ; file.read char * i,sizeof int ; cout The data stored is i endl; file.seekp 20,ios::cur ; file.read char * i,sizeof int ; cout The data stored is i endl; cout current byte number: file.tellp endl; return 0; current byte number:60 The data stored is 15 The data stored is 95 The data stored is 21 current byte number:88 * int main int x 77; cout 1座机电话号码01座机电话号码0\n; cout.fill # ; cout.width 10 ; cout x ; cout.width 10 ; cout.setf ios::left ; cout.fill $ ; cout x \n; int y 0x2a; cout 1座机电话号码01座机电话号码0\n; cout.unsetf ios::left ; cout.fill % ; cout.width 10 ; cout y ; cout.unsetf ios::right ; cout.width 10 ; cout.setf ios::left ; cout.fill $ ; cout y \n; return 0; * int main int a 5,b 7,c -1; float x 67.8564,y -789.124; char ch A; long n 1234567; unsigned u 65535; cout a b endl; cout setw 3 a setw 3 b \n;
您可能关注的文档
- SCR催化剂(脱销钛白粉)实用总结分析.ppt
- SD8000--基础重点.ppt
- SDC系列智能型除湿装置说明书重点.doc
- IBEACON移动书店项目重点.ppt
- IBT听力---lecture词汇重点.doc
- seafoodknown重点.doc
- IB自选模块第二章第二节重点.ppt
- ICD-10各章节思考题分析.doc
- IChOLand07-04重点.doc
- SectionA1八年级下册第二单元课件重点.ppt
- 注册验船师高频真题题库2025.docx
- 注册验船师高频题库带解析2025.docx
- 注册验船师考试必备资料2025.docx
- 注册验船师精选题库带分析2025.docx
- 注册验船师考前冲刺必刷题附答案2025.docx
- 新高考生物二轮复习讲练测第10讲 人体的稳态与免疫调节(讲练)(原卷版).docx
- 新高考生物二轮复习讲练测第13讲 生物技术与工程(讲练)(原卷版).docx
- 新高考生物二轮复习讲练测第9讲 神经调节与体液调节(讲练)(原卷版).docx
- 新高考生物二轮复习讲练测第7讲 遗传的基本规律与伴性遗传(检测)(原卷版) .docx
- 新高考生物二轮复习讲练测第13讲 生物技术与工程(检测)(原卷版).docx
文档评论(0)