首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

fstream使用的有关问题

2012-02-29 
fstream使用的问题#includefstream#includeiostreamusing namespace stdint main(){fstream f(D:\\s

fstream使用的问题
#include<fstream>
#include<iostream>
using namespace std;

int main()
{
  fstream f("D:\\s.txt",ios::out);
  for(int i=0;i<100;++i) f.write((char*)&i,4);
  f.close();
  fstream fa("D:\\s.txt",ios::in);
  int l;
  for(int z=0;z<100;++z) fa.read((char*)&l,4),cout<<l<<" ";
  fa.close();
return 0;
}
为什么这样输出的不是1 2 3 4 5……99 100
而是1 2 3 4……24 25 25 25 25 25……呢



这是我看到别人的一个问题,但是看了很久没看出来为什么read()调用了25次以后就返回错误了。

[解决办法]
知道了,文本模式把26当^Z文件结束了...

热点排行