自考新教材-p313
作者:互联网
源程序:
#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;
}
运行结果:
标签:cout,outFile,新教材,char,stu,int,p313,id,自考 来源: https://www.cnblogs.com/duanqibo/p/12263439.html