我正在尝试编写一个程序,当程序正在执行操作(例如:搜索、更新或添加)时,它应该是直接访问。程序不应按顺序读取所有记录以达到一条记录。
#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");
}
我卡在这里我无法按顺序阅读我该如何解决这个问题