On-line: гостей 0. Всего: 0 [подробнее..]
Программисты всех стран, объединяйтесь!

АвторСообщение



ссылка на сообщение  Отправлено: 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?

Спасибо: 0 
ПрофильЦитата Ответить
Ответов - 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.

Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 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

Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 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.

Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 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 .

Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 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.


Спасибо: 0 
ПрофильЦитата Ответить
Ответ:
1 2 3 4 5 6 7 8 9
большой шрифт малый шрифт надстрочный подстрочный заголовок большой заголовок видео с youtube.com картинка из интернета картинка с компьютера ссылка файл с компьютера русская клавиатура транслитератор  цитата  кавычки моноширинный шрифт моноширинный шрифт горизонтальная линия отступ точка LI бегущая строка оффтопик свернутый текст

показывать это сообщение только модераторам
не делать ссылки активными
Имя, пароль:      зарегистрироваться    
Тему читают:
- участник сейчас на форуме
- участник вне форума
Все даты в формате GMT  3 час. Хитов сегодня: 19
Права: смайлы да, картинки да, шрифты да, голосования нет
аватары да, автозамена ссылок вкл, премодерация откл, правка нет