C++二进制在文件中读取对象信息报错
intmain(){Colleaguec("CFO","读书",31,'F',"安迪");ofstreamb;b.open("colleague.txt",ios::bi...
int main()
{
Colleague c("CFO","读书",31,'F',"安迪");
ofstream b;
b.open("colleague.txt",ios::binary|ios::app);
b.write((char*)&c,sizeof(Colleague));
b.close();
Colleague clg;
int i;
fstream a;
a.open("colleague.txt",ios::binary|ios::in);
a.read((char*)&clg,sizeof(Colleague));
cout<<clg.GetBusiness()<<endl;
}
这些是代码,有一点补充的是,如果文件在运行前是空的就可以运行,但如果第二次或以上运行就会崩掉,求大神解答 展开
{
Colleague c("CFO","读书",31,'F',"安迪");
ofstream b;
b.open("colleague.txt",ios::binary|ios::app);
b.write((char*)&c,sizeof(Colleague));
b.close();
Colleague clg;
int i;
fstream a;
a.open("colleague.txt",ios::binary|ios::in);
a.read((char*)&clg,sizeof(Colleague));
cout<<clg.GetBusiness()<<endl;
}
这些是代码,有一点补充的是,如果文件在运行前是空的就可以运行,但如果第二次或以上运行就会崩掉,求大神解答 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询