So to start off, the goal of this function below is to read each line in the text file (TitanData.txt). Each line has 3 pieces of information: Age, Passenger Class, and if the passenger survived (saved as "TRUE" or "FALSE") in order. I've created 3 vectors: vector Age, vector PassengerClass, vector Survived. The issue seems to be that the push_back functions aren't working properly. I've been looking for solutions for hours and I have yet to come across one so hopefully I can get an answer here.
The function is below:
void ReadFromFile(vector<int> Age, vector<string> PassengerClass, vector<bool> Survived)
{
bool survived;
int age;
string Passenger_Class;
string val1, val2, val3;
ifstream infile;
infile.open("TitanicData.txt");
if (infile)
{
while (infile >> val1 >> val2 >> val3)
{
age = stoi(val1);
Age.push_back(age);
Passenger_Class = val2;
PassengerClass.push_back(val2);
if (val3 == "TRUE")
{
survived = true;
Survived.push_back(true);
}
if (val3 == "FALSE")
{
survived = false;
Survived.push_back(false);
}
}
infile.close();
}
}