Hi!
I'm trying to read in a list from a file into a vector of struct. It reads in the first row normally and then like this:
![Posted Image]()
and it reads the last row two times. Don't really know why. Thanks for any help!
The original file looks like this:
John|Smith|johsmi01|1.67|
Hanna|Barbera|hanbar01|1.45|
Johanna|Smith|johsmi02|1.56|
Bob|Taylor|bobtay01|1.76|
I'm trying to read in a list from a file into a vector of struct. It reads in the first row normally and then like this:

and it reads the last row two times. Don't really know why. Thanks for any help!
The original file looks like this:
John|Smith|johsmi01|1.67|
Hanna|Barbera|hanbar01|1.45|
Johanna|Smith|johsmi02|1.56|
Bob|Taylor|bobtay01|1.76|
void loadList(vector <Person> &persons)
{
string filename;
Person newPerson;
cout << "Reading list from a text file" << endl;
cout << "\nType in the filename you want to open: " << endl;
cin >> filename;
ifstream inFile(filename.c_str());
persons.clear();
if(inFile.is_open())
{
do
{
getline(inFile, newPerson.firstName, DELIM);
getline(inFile, newPerson.lastName, DELIM);
getline(inFile, newPerson.sign, DELIM);
inFile >> newPerson.height;
inFile.get();
persons.push_back(newPerson);
}while(!inFile.eof());
inFile.close();
cout << "The file has opened!" << endl;
}
else
{
cout << "The file couldn't be opened!" << endl;
}
};