struct person { string Name; double Salary; }; // end struct void SearchFileSequentially(string FileName, string DesiredName, person& DesiredPerson, bool& Found) // -------------------------------------------------------- // Searches a text file sequentially for a desired person. // Precondition: FileName is the name of a text file of // names and data about people. Each person is represented // by two lines in the file: The first line contains the // person's name, and the second line contains the person's // salary. DesiredName is the name of the person sought. // Postcondition: If DesiredName was found in the file, // DesiredPerson is a structure that contains the person's // name and data, and Found is true. Otherwise, Found is // false and DesiredPerson is unchanged. The file is // unchanged and closed. // -------------------------------------------------------- { ifstream InFile(FileName); string NextName; double NextSalary; Found = false; while ( !Found && getline(InFile, NextName) ) { InFile >> NextSalary >> ws; // skip trailing eoln if (NextName == DesiredName) Found = true; } // end while if (Found) { DesiredPerson.Name = NextName; DesiredPerson.Salary = NextSalary; } // end if InFile.close(); } // end SearchFileSequentially