I've written some code where the program reads in information from a file (here's the file)
5
Franks,Tom 2 3 8 3 6 3 5
Gates,Bill 8 8 3 0 8 2 0
Jordan,Michael 9 10 4 7 0 0 0
Bush,George 5 6 5 6 5 6 5
Heinke,Lonnie 7 3 8 7 2 5 7
and puts it into two arrays. One for names and one for numbers. Then totals up the numbers and stores it in the data array. Now I need to change all the arrays into Vectors and I'm confused on how to do that. I know that I need to use push_back but I'm confused on how to start.
Here's the code with the arrays:
int data[50][8];
string names[50];
int const TTL_HRS = 7;
ifstream fin;
fin.open("empdata.txt");
if (fin.fail()) {
cout << "ERROR";
}
int sum = 0;
int numOfNames;
fin >> numOfNames;
for (int i = 0; i < numOfNames; i++) {
fin >> names[i];
data[i][7] = 0;
for (int j = 0; j < 7; j++) {
fin >> data[i][j];
data[i][TTL_HRS] += data[i][j];
}
}
fin.close();
return numOfNames;
}
I know that I have to make the arrays vectors. So I'll have
vector<vector<int>>data;
and
vector<string>names;
but I'm not sure how to go about filling them.