Link to home
Start Free TrialLog in
Avatar of edelossantos
edelossantos

asked on

Employee.cpp

>> Need checked, please advise.  Del

#include <iostream>
#include <fstream>

using namespace std;

int main(void)
{
   
    struct employee {
         char name[64];
         int age;
         int sex;
         int phone;
         float salary;
    } worker = {"peter", 2, 25000};

    ofstream emp_file("employee.DAT", ios::app);

    emp_file.write((char *) &worker, sizeof(employee));

    ifstream mp_file("employee.DAT");
    while (!mp_file.eof())
    {
    mp_file.read((char *) &worker, sizeof(employee));

    cout << "Name: " << worker.name << endl;
      cout << "Sex: " << worker.sex << endl;
    cout << "Age: " << worker.age << endl;
      cout << "Phone: " << worker.phone << endl;
    cout << "Salary: " << worker.salary << endl;
    }
   
    return 0;

}

**********************
employee.DAT
**********************

Name: Enrique (Del) De Los Santos

Sex: Male

Age: 41

Phone: USA-COMP

************************
SOLUTION
Avatar of novitiate
novitiate

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of edelossantos
edelossantos

ASKER

Thank you to all. Del