I am trying to take an inputted file that has two different sets of numbers and put them into two separate vectors. I'm not sure why I am unable to print out either vectors. Please help
Here is the file I'm trying to input and convert into two arrays (first section with 7 numbers is the ID's and the second section with 2 numbers are the test scores):
0773950 56
0773259 75
0732441 57
0772208 27
0775338 69
0763847 47
0771716 49
0773073 45
0774237 49
0775358 93
0763975 43
0779363 20
0775159 85
0777195 64
0764343 68
0773434 44
0766469 47
0777249 56
0777999 38
0777063 46
0774446 41
0710748 79
0771375 61
0774925 69
0774073 74
0773000 60
0763776 38
0776677 65
0763218 50
0773144 49
0773542 75
0774133 87
And here is the code I have so far:
#include <fstream>
#include <iostream>
#include <vector>
using namespace std;
int main(){
vector<int> id;
vector<int> scores;
int data1, data2;
ifstream infile("Project.txt");
if (!infile.is_open()){
cout << "File Error" << endl;
return 1;
}
while (infile.eof()){
infile >> data1 && infile >> data2;
id.push_back(data1);
scores.push_back(data2);
}
infile.close();
for (int i = 0; i < id.size(); i++){
cout << "Here are the id's: " << id[i] << endl;
}
cout << "\n";
for (int i = 0; i < scores.size(); i++){
cout << "Here are the scores: " << scores[i] << endl;
}
return 0;
}