I have created a program that you search all the users that have ever used the program, but you need to enter your details to search. It is all fine and not buggy, but I have one thing I would like to know how to do. I would like to know so that when it searches it will enter everything on the line the string was found and the line below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
inFile.open("data.txt");
cout << "\n";
cin.get(entr); //dont worry about this. this is just something you don't need to know about.
cout << "\nYou may now search a user\n";
cout << "\nEnter a students first or last name ((Case sensitive))\n";
getline (cin, search);
cout << "\n Searching for " << search <<"\n";
{
size_t pos;
while(inFile.good())
{
getline(inFile,line); // get line from file
pos=line.find(search); // search
if(pos!=string::npos) // string::npos is returned if string is not found
{
cout << search << " Found!"; //this is where I want it to display the line the string was found and the line below, because the line below has the age.
break;
}
}