// 6学生的档案生成程序,从屏幕读取学生信息,包括(姓名、学号,学校、班级,出生年月、专业、特长)等信息,存入stduend.dat文件中。
时间: 2024-05-27 09:13:33 浏览: 16
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
struct Student{
string name;
string id;
string school;
string clazz;
string birth;
string major;
string speciality;
};
int main(){
ofstream outfile("student.dat", ios::binary);
if(!outfile){
cout << "Cannot open file." << endl;
return 1;
}
Student student;
while(true){
cout << "Name: ";
getline(cin, student.name);
if(student.name.empty()){
break;
}
cout << "ID: ";
getline(cin, student.id);
cout << "School: ";
getline(cin, student.school);
cout << "Class: ";
getline(cin, student.clazz);
cout << "Birth: ";
getline(cin, student.birth);
cout << "Major: ";
getline(cin, student.major);
cout << "Speciality: ";
getline(cin, student.speciality);
outfile.write((char*)&student, sizeof(student));
}
outfile.close();
return 0;
}
相关推荐
![cpp](https://img-home.csdnimg.cn/images/20210720083646.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)