// 6学生的档案生成程序,从屏幕读取学生信息,包括(姓名、学号,学校、班级,出生年月、专业、特长)等信息,存入stduend.dat文件中。
时间: 2024-05-27 21:13:33 浏览: 67
学生信息管理系统, 实现学生信息包括:学号、姓名、性别、年龄、班级等信息
5星 · 资源好评率100%
#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;
}
阅读全文