将out.open("xs.dat",ios::out|ios::binary);该段代码改为实现保存文件为txt文本文件
时间: 2024-02-07 20:02:27 浏览: 177
将该段代码修改为:
```
out.open("xs.txt", ios::out);
```
这将以文本模式打开名为"xs.txt"的文件,以便将数据保存为文本。
相关问题
将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文本文件
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;
}
阅读全文