I am trying to read from a file and insert the data into a vector. The file looks like:
16
0100
0111
0111
0001
0100
1011
1010
0010
0110
1001
1100
1001
1100
0101
0101
0001
I want my vector to look something like:
16 0 1 0 0 0 1 1 1 0 1 1 1...
My code looks like this:
void readFile(string name){
ifstream fin;
vector<int> graphData;
int y;
fin.open(name);
if (!fin.is_open()){
cout << "Error: Could not open data.";
}
else{
while(!fin.eof()){
fin >> y;
graphData.push_back(y);
}
}
fin.close();
for(int i = 0; i < graphData.size(); ++i){
cout << graphData[i] << " ";
}
}
I am pretty sure the issue is with me defining y and then trying to push that in. But when I run the code nothing is outputted like the vector is empty.