Vector of Structs

I am trying to fill a vector with structs that are read in from a .txt file. This is what I have so far but for some reason it won't read in the info.

#include <iostream>
#include <string>
#include <fstream>
#include <vector>
using namespace std;

struct PersonalRecords
{
string lastName;
string firstName;
char gender;
int age;
};

void fillVector (vector<PersonalRecords>&, ifstream& inFile);

int main()
{
ifstream inFile;
vector<PersonalRecords> personalInfo;
string personsFile;
char fileName [50];



cout << "Enter the name of the file with the personal records:" << endl;
cin.getline(fileName, 50);
inFile.open(fileName);

fillVector (personalInfo, inFile);

return 0;
}

void fillVector (vector<PersonalRecords>& personalInfo, ifstream& inFile)
{
int index = 0;

while (inFile)
{
getline(inFile, personalInfo[index].lastName);
inFile >> personalInfo[index].firstName;
inFile >> personalInfo[index].gender;
inFile >> personalInfo[index].age;
index++;
}

inFile.close();
}
1
2
3
//Push_back() with an empty struct.
//Can't edit a vector with nothing in it.
personalInfo.push_back( PersonalRecords() );
Topic archived. No new replies allowed.