第10章 C++ IO流标准库.pptVIP

  • 5
  • 0
  • 约1.75万字
  • 约 50页
  • 2017-11-17 发布于河南
  • 举报
第10章CIO流标准库

P303例10.8同时读写一个二进制文件 #include iostream.h #include fstream.h void main() { int a[5]={ 4, 2, 0, 6, 5 }, i; fstream iofile(data3.dat,ios::in|ios::out|ios::binary); //定义一个fstream类对象 for(i=0;i5;i++) { iofile.write((char*)a[i], sizeof(int)); a[i]=-1; } iofile.seekg(0,ios::beg); //设置读指针 for(i=0;i5;i++) { iofile.read((char*)a[i],sizeof(int)); couta[i] ; } coutendl; } 生成data1.dat文件的内容 4 2 0 6 5 istream::seekg函数和 istream::tellg()函数 用法与seekp和tellp函数相同: 原型: istream seekg( long pos ); istream seekg( long off, ios::seek_dir ); long tellg(); 作业:

文档评论(0)

1亿VIP精品文档

相关文档