本文需求来自于留学生作业
#include <iostream>
#include <string>
#include <fstream>
#include <list>
using namespace std;
const int FIRST_NAME_LEN = 10;
const int SECOND_NAME_LEN = 10;
const int SOCIAL_SECURITY_LEN = 9;
const int DEP_ID_LEN = 9;
struct Record
{
char m_firstName[FIRST_NAME_LEN] ;
char m_secondName[SECOND_NAME_LEN] ;
char m_socialSecurity[SOCIAL_SECURITY_LEN] ;
char m_departmentID[DEP_ID_LEN] ;
int m_years;
int m_salary;
int m_averageSalary;
int m_averageYears;
Record(void);
friend istream& operator>>(istream& in, Record& record);
friend ostream& operator<<(ostream& out, const Record& record);
ofstream& Record::WriteToBinaryFile(ofstream& out) const;
ifstream& Record::ReadFromBinaryFile(ifstream& fin);
void WriteToOstream(ostream& os) const;
};
///////////////////////////////////////////////
//在这里实现你的代码
///////////////////////////////////////////////
int main(int arcg, char** argv)
{
list<Record> listEmployee;
cout<<"ReadTextEmployee from employee.in"<<endl;
if (!ReadTextEmployee("employee.in", listEmployee))
{
return -1;
}
PrintAllEmployee(listEmployee);
cout<<"WriteEmployeeToBinaryFile to employee.binary\n"<<endl;
WriteEmployeeToBinaryFile(listEmployee, "employee.binary");
listEmployee.clear();
cout<<"ReadBinaryEmployee from employee.binary"<<endl;
ReadBinaryEmployee("employee.binary", listEmployee);
PrintAllEmployee(listEmployee);
CalculateAverage(listEmployee);
PrintAllEmployeeWithAverage(listEmployee);
WriteEmployeeToTextFile(listEmployee, "employee.out");
return 0;
}
输出如下: