I want my program to look for a student's name in a text file and then display that particular line.
I'm just getting the first line of the text file as output and not the line I'm looking for.
void OTHERS::search_acc()
{
string srch;
string line;
fstream Myfile;
Myfile.open("STUDENTS", ios::in|ios::out);
cout << "\nEnter Student Name: ";
cin.ignore();
getline(cin, srch);
if(Myfile.is_open()) //The problem is in this if block
{
getline(Myfile, line);
line.find(srch, 0);
cout << "\nSearch result is as follows: \n" << line << endl;
}
else
{
cout << "\nSearch Failed... Student not found!" << endl;
system("PAUSE");
}
}
Also, is it possible to return the location of the string I'm looking for in the text file?