I'm trying to write a program, when the program is performing an operation (Example: search, update, or add), it should be direct access. The program should not read all the records sequentially to reach a record.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
struct Student{
int Id;
int Money;
int Age;
char name[15];
};
void main(){
Student buffer;
ofstream BinaryFile("student", ios::binary);
ifstream WorkerText("worker.txt");
//-------------------------------------------------------------------------------------------------------------
while( WorkerText.good() ){
WorkerText>> buffer.Age >> buffer.name >> buffer.name >> buffer.name;
BinaryFile.write( (char *) &buffer, sizeof(Student) );
}
BinaryFile.close();
//-------------------------------------------------------------------------------------------------------------
ifstream ReadBinary( "student", ios::binary | ios::out );
while( BinaryFile.good() ){
ReadBinary.read((char*)&buffer,sizeof(Student));
cout<<buffer.Age;
}
//-------------------------------------------------------------------------------------------------------------
system("pause");
}
I stucked here I could not read sequentially how can I solve this