reading selective data from a file

#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..
Last edited on
just write each data on a separate line.......and remember which line contains what data......hope that helps
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.
mcrist wrote:
... use a searching algorithm (bubble/binary/ or whatever you want) ...
I don't know of any bubble search.

What are you trying to do, and what exactly is the problem timmy? (Also, please format your code!)
Last edited on
>.< Bubble sort fail...
Topic archived. No new replies allowed.