将void save::savestudent(){ int i; ofstream out,out1; out.open("xs.txt",ios::out); out1.open("kcchain.dat",ios::out|ios::binary); if(!out){ cerr<<"不能打开xs文件"<<endl; exit(1); } for(i=0;i<=totalxs-1;i++){ out.write((char*)&xs[该段代码改为实现保存文件为txt文本文件
时间: 2024-03-04 14:51:28 浏览: 102
StudentManagmentwithHibernate:init
void save::savestudent(){
int i;
ofstream out, out1;
out.open("xs.txt", ios::out);
out1.open("kcchain.dat", ios::out | ios::binary);
if (!out) {
cerr << "不能打开xs文件" << endl;
exit(1);
}
for (i = 0; i <= totalxs - 1; i++) {
out << xs[i].id << " " << xs[i].name << " " << xs[i].score << endl;
out1.write((char*)&xs[i], sizeof(xs[i]));
}
out.close();
out1.close();
cout << "保存学生信息成功!" << endl;
}
阅读全文