#include<iostream>
#include<conio.h>
#include<fstream>
#include<string>
using namespace std;
int main()
{
string name;
int roll,marks,i;
ofstream myfile[2];
myfile[0].open("student1.txt",ios::out);
myfile[1].open("student2.txt",ios::out);
for(i=0;i<2;i++)
{
cout<<"enter the name";
getline(cin,name);
myfile[i]<<name;
cout<<"enter the roll number";
cin>>roll;
cin.get();
myfile[i]<<roll;
cout<<"enter the marks";
cin>>marks;
cin.get();
myfile[i]<<marks;
myfile[i].close();
}
ifstream urfile[2];
urfile[0].open("student1.txt",ios::in);
urfile[1].open("student2.txt",ios::in);
cout<<"enter the roll number of student whose detail you wish to know";
int query;
cin>>query;
i know this code is totally incomplete.but i failed to proceed after this.i tried to google around object serialization but failed to understand it.plz help me out with this code.even a hint is appreciated..
Could you just create some sort of data structure (like an ArrayList or vector of elements) and search those from the memory or is the data file too large? I would create a class called Student, store the data for each student read in from the data file, and use a searching algorithm (bubble/binary/ or whatever you want) to acquire the result.