/* Filename: reademp.cpp Author: Br. David Carlson Date: February 4, 1998 Last Revised: February 21, 2013 This program reads the emp.dat binary file of employee records, as created by the makeemp program. The data for the records is displayed on the screen. Tested with: Microsoft Visual C++ 2008 g++ under Linux */ // iostream is indirectly included via employee.h #include // needed for files #include "employee.h" // needed for EmployeeType void DisplayFile(fstream & InFile); int main(void) { fstream InFile; InFile.open("emp.dat", ios::in | ios::binary); if (InFile.fail()) { cerr << "Could not open file emp.dat" << endl; exit(1); } DisplayFile(InFile); InFile.close(); return 0; } /* Given: InFile A binary file stream already opened for input. Task: To read records of employee data from InFile and display them on the screen. Return: InFile The modified file stream. */ void DisplayFile(fstream & InFile) { int RecordSize, Count; EmployeeType Employee; Count = 0; RecordSize = sizeof(Employee); InFile.read(reinterpret_cast (&Employee), RecordSize); while (! InFile.fail()) { PrintEmployee(Employee); Count++; if (Count == 21) { Count = 0; cout << endl << "Press ENTER to go on" << endl; cin.get(); } InFile.read(reinterpret_cast (&Employee), RecordSize); } if (Count != 0) { cout << endl << "Press ENTER to go on" << endl; cin.get(); } }