0
点赞
收藏
分享

微信扫一扫

自考新教材-p313

嚯霍嚯 2022-06-08 阅读 171

源程序:

#include<iostream>
#include<fstream>
using namespace std;
class CStudent
{
public:
char id[11];
char name[21];
int score;
};
int main()
{
CStudent stu;
ofstream outFile("c:\\tmp\\students.dat", ios::out | ios::binary);
if (!outFile)
{
cout << "创建文件失败" << endl;
return 0;
}
cout << "请输入:学号 姓名 成绩(以Ctrl+Z结束输入)\n";
while (cin >> stu.id >> stu.name >> stu.score)
outFile.write((char*)&stu, sizeof(stu));
outFile.close();
system("pause");
return 0;
}

运行结果:

自考新教材-p313_创建文件

 


举报

相关推荐

0 条评论