1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
void search (){
ifstream in_File ("Student.txt");
fstream out_File ("Temp.txt", ios::in | ios::out);
if(!in_File.is_open()){
cout << "File failed to open" << endl;
}
string strSN;
string strAge;
string line;
system ("cls");
int count = 0;
while (getline(in_File, line)){
stringstream ss (line);
stringstream strGender;
stringstream strCN;
stringstream stremail_add;
stringstream strProg;
getline(ss, strSN, ',');
stu.student_number = atoi(strSN.c_str());
getline(ss, stu.first_name, ',');
getline(ss, stu.middle_name, ',');
getline(ss, stu.last_name, ',');
strGender << stu.gender;
strGender >> stu.strGender1;
getline(ss, stu.strGender1, ',');
getline(ss, strAge, ',');
stu.age = atoi(strAge.c_str());
stu.student_number = atoi(strSN.c_str());
getline(ss, stu.birth, ',');
getline(ss, stu.address, ',');
strCN << stu.contact_number;
strCN >> stu.strCN1;
getline(ss, stu.strCN1, ',');
stremail_add << stu.email_add;
stremail_add >> stu.stremail_add1;
getline(ss, stu.stremail_add1, ',');
getline(ss, stu.father_name, ',');
getline(ss, stu.mother_name, ',');
strProg << stu.program;
strProg >> stu.strProgram;
getline(ss, stu.strProgram, ',');
out_File << "==================================================================================================" << endl << endl
<< stu.student_number << endl
<< stu.first_name << endl
<< stu.middle_name << endl
<< stu.last_name << endl
<< stu.strGender1 << endl
<< stu.age << endl
<< stu.birth << endl
<< stu.address << endl
<< stu.strCN1 << endl
<< stu.stremail_add1 << endl
<< stu.father_name << endl
<< stu.mother_name << endl
<< stu.strProgram << endl;
int key;
while(!out_File.eof()){
cout << "Enter SN ";
cin>> key;
if(key == stu.student_number){
cout << "==================================================================================================" << endl << endl
<< stu.student_number << endl
<< stu.first_name << endl
<< stu.middle_name << endl
<< stu.last_name << endl
<< stu.strGender1 << endl
<< stu.age << endl
<< stu.birth << endl
<< stu.address << endl
<< stu.strCN1 << endl
<< stu.stremail_add1 << endl
<< stu.father_name << endl
<< stu.mother_name << endl
<< stu.strProgram << endl;
}
}
in_File.close();
}
}
| |