I am trying to read in data from a .txt file and use it to create several instances of a struct. I want to do this progromatically via code, as opposed to declaring each instance of the struct manually in a pre determined way (I want it to work for any number of structs being created/data rows in the input file).
The input file contains a name and then three doubles. Each new line is a new person ("input.txt"):
Peter 1.0 2.0 3.0
James 4.0 5.0 6.0
Code:
struct Person 
{
  string name;
  vector<double> numbers;
};
int main()
{
ifstream inStream("input.txt");
vector<Person> vecPerson; // vector to hold structs
string nameInput;
double num1;
double num2;
double num3;
int i =0;
while( inStream.peek() != EOF )
{
    inStream >> nameInput >> num1 >> num2 >> num3; //read in data to variables
    //create struct
    Person person[i];
    person[i].name = nameInput;
    person[i].numbers[0] = num1;
    person[i].numbers[1] = num2;
    person[i].numbers[2] = num3;
    i++;
    vecPerson.push_back(person[i]);
}  
This code gives a segfault. The line Person person[i]; clearly isn't right syntactically. I am not sure how I create a different name for the struct instance for each loop of the while loop.
How do I do this?
 
    