文件操作的程序运行时为什么文件打不开啊?
#include<fstream.h>#include<string.h>
#include<stdlib.h>
int main()
{
struct student{
int num;
char na[10];
int tel;
int de;
}stu[]={1,"licaix",1322,205,
2,"xumin",1322,205,
3,"dingxiao",13222,205};
ofstream ofp("stu.dat",ios::binary);
if(!ofp){
cerr<<"can't open stu.dat!"<<endl;
abort();
}
int i;
for(i=0;i<=2;i++)
ofp.write((char*)&stu[i],sizeof(student));
student newstu={4,"huangmin",13222,205};
ofp.write((char*)&newstu,sizeof(student));
student xiugai={2,"xumin",132226,206};
ofp.seekp(sizeof(student));
ofp.write((char*)&xiugai,sizeof(student));
ofp.close();
fstream fp("stu.dat",ios::binary);
if(!fp){
cerr<<"can't open stu.dat!"<<endl;
abort();
}
student st[4];
fp.read((char*)&st[i],sizeof(student));
for(i=0;i<4;i++)
cout<<st[i].num<<""<<st[i].na<<""<<st[i].tel<<""<<st[i].de<<endl;
fp.close();
return 0;
}
程序为什么运行结果是student。dat打不开啊?