Автор | Сообщение |
|
Отправлено: 14.10.12 14:16. Заголовок: Binary and random access file
The program should store the employee’s records in a random access file and supports a variety of operations such as add a new employee record, modify an employee record, search and display employee records, etc. & You are to use a binary file to keep the records of all employees. Identify and define a suitable structure to keep your employee record. as this mean isnt const int RecordSize = ... void readRecord(Employee *theEmployee , int index){ // Note that you have an index instead of size ifstream inFile; inFile.open( "employee.txt" ); if( inFile.is_open() ){ if(inFile.seekg(index * RecordSize)){ // index * RecordSize is the offset of your record getline( inFile , theEmployee->EmployeeID ); // Note that you do not have an array anymore getline( inFile , theEmployee->EmployeeName ); getline( inFile , theEmployee->EmployeeDepartment ); getline( inFile , theEmployee->EmployeeDOB ); getline( inFile , theEmployee->EmployeeAddress ); inFile >> theEmployee->EmployeeWorkHours; inFile >> theEmployee->PayRate; inFile >> theEmployee->totalSalary; } inFile.close(); } } } isnt the coding correct ? as we use the binary file to keep the record isnt mean when ofstream . using ios :: binary thats all?
|
|
|
Ответов - 5
[только новые]
|
|
|
Отправлено: 14.10.12 17:27. Заголовок: You should correctly..
You should correctly set the file open mode specifying that it is a binary file and is opened for read/write (I/O) operations.
|
|
|
|
Отправлено: 15.10.12 06:28. Заголовок: mean infile.open (..
mean infile.open ("employee.txt" , ios:: binary )? i get an fatal error that stated 1 unresolve external
|
|
|
|
Отправлено: 15.10.12 13:55. Заголовок: It means that you ar..
It means that you are using a name that is undefined. Usually such error message conttains a reference to a name that is undefined.
|
|
|
|
Отправлено: 15.10.12 14:21. Заголовок: i solved it . but as..
i solved it . but as coder777 said in forum. i cant read any data in case i use random access file. void readRecord(Employee *theEmployee , int &index){ // Note that you have an index instead of size ifstream inFile; string filename; cout << "Enter filename to be read : "; getline( cin, filename ); inFile.open( filename.c_str() , ios :: binary ); if( inFile.is_open() ){ if(inFile.seekg(index * RecordSize)){ // index * RecordSize is the offset of your record getline( inFile , theEmployee->EmployeeID ); // Note that you do not have an array anymore getline( inFile , theEmployee->EmployeeFirstName ); getline( inFile , theEmployee->EmployeeLastName ); getline( inFile , theEmployee->EmployeeDepartment ); getline( inFile , theEmployee->EmployeePosition ); inFile >> theEmployee->EmployeeWorkHours; inFile >> theEmployee->PayRate; inFile >> theEmployee->totalSalary; } inFile.close(); } } erm , now what my problem ? i cannot display the data inside my file .
|
|
|
|
Отправлено: 15.10.12 16:45. Заголовок: I already showed you..
I already showed you what functions you should use with a file opened in the binary mode. So I do not understand what you are doing. There is such book by Herb Schildt "Herb Shildt's C++ Programming Cookbook". I think it will be useful if you will read this book.
|
|
|
|