Welcome

首页 / 软件开发 / C++ / C++读写二进制流文件的例子

C++读写二进制流文件的例子2011-04-06//读写2进制流文件

#include <fstream.h>
#include <iostream.h>
#include <stdlib.h>
void main()
{
ofstream f1("wr1.dat");
if(!f1)
{
cerr<<"wr1.dat file not open!"<<endl;
exit(1);
}
//f1.seekp(beg);
for(int i=0;i<21;i++)
f1<<i<<" ";
f1.close();
ifstream f2("wr1.dat",ios::in|ios::nocreate);
if(!f1)
{
cerr<<"wr1.dat file not open!"<<endl;
exit(1);
}
int x;
while(f2>>x)
cout<<x<<" ";
cout<<endl;
f2.close();
}