- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
C第08章输入输出流对象(2013年12月17日)概要1
* 文件的随机读写:文件打开以后,系统自动生成两个隐含的流指针:读指针和写指针。在输入文件流类中,有关读指针的函数如下: 移动读指针函数 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) { coutexam.dat can’t openendl; abort(); } for(int i=0;i15;i++) file.write((char*)i,sizeof(int)); streampos pos=file.tellp(); coutcurrent byte number: posendl; for(i=15;i45;i++) file.write((char*)i,sizeof(int)); file.seekg(pos); file.read((char*)i,sizeof(int)); coutThe data stored is iendl; file.seekp(0,ios::beg); for(i=80;i100;i++) file.write((char*)i,sizeof(int)); file.seekg(pos); file.read((char *)i,sizeof(int)); coutThe data stored is iendl; file.seekp(20,ios::cur); file.read((char *)i,sizeof(int)); coutThe data stored isiendl; coutcurrent 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; cout12345678901234567890\n; cout.fill(#); cout.width(10); coutx=; cout.width(10); cout.setf(ios::left); cout.fill($); coutx\n; int y=0x2a; cout12345678901234567890\n; cout.unsetf(ios::left); cout.fill(%); cout.width(10); couty=; cout.unsetf(ios::right); cout.width(10); cout.setf(ios::left); cout.fill($); couty\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; coutabendl; coutsetw(3)asetw(3)b\n; coutx,yendl; coutsetw(10)x,setw
您可能关注的文档
- Business English 1概要1.ppt
- Business Communication Essentials 商业传意 Ch14概要1.pptx
- Business Communication Essentials 商业传意 Ch2概要1.pptx
- business English writing概要1.pptx
- Business ethics概要1.pptx
- business English train materials商务英语中级培训教材概要1.ppt
- Business Communication Essentials 商业传意 Ch5概要1.pptx
- business Cycle最终概要1.ppt
- business letters商务信函概要1.ppt
- Business Translation 1概要1.ppt
最近下载
- 三阶魔方F2L公式研究及记忆方法.pdf
- 装表接电工考试(技师)习题库(第1部分).pdf VIP
- 幼儿园-健康-危险的食品(预防食物中毒)-课件(互动版).pptx
- 人教版小学四年级音乐下册《第二单元 五十六朵花》大单元整体教学设计[2022课标].docx
- Q∕GDW 11316-2018 高压电缆线路试验规程.pdf
- 心房颤动患者左心耳封堵术后护理查房.pptx VIP
- 0723S03016-监察法学-理论课程教学大纲-申静、李芹.docx VIP
- 阜外心血管病医院手术分级目录2015版.docx VIP
- DB5328T 44-2025 珠芽黄魔芋栽培技术规程.docx VIP
- 2025年辽宁事业单位考试真题及答案.docx
文档评论(0)