

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


#include
void student::read_file() { fstream fp; fp.open("3.txt",ios::in); while(!fp.eof()) { buffer.erase(); getline(fp,buffer); unpack(); if(!fp.eof()&& buffer[0]!='') display(); } fp.close(); } void student::unpack() { int i=0; usn.erase(); while(buffer[i]!='|') usn+=buffer[i++]; i++; name.erase(); while(buffer[i]!='|') name+=buffer[i++]; i++; sem.erase(); while(buffer[i]!='$') sem+=buffer[i++]; } void student::display() { cout<<"Usn:"<<usn<<" Name:"<<name<<" Sem:"<<sem<<endl; } int student::search1(string regno) { fstream fp; int recno=0,flag=0,pos=0; fp.open("3.txt",ios::in); while(!fp.eof()) { buffer.erase(); getline(fp,buffer); if(buffer[0]!='') //check the buffer ==* recno++; unpack(); if(usn==regno) { cout<<"\nRecord is "<<buffer; cout<<"\nRecord Found at Position "<<recno; pos=fp.tellg(); flag=1; return pos; } } fp.close(); if(!flag)