getline with ints C++
- by Mdjon26
I have a file
0 3 2
1 2 3
4 5 6
6 8 1
Where the first number for each line is the row, the second number is the column, and the third number is the data contained in that row, column. This will be a given [8][8] array so I have already initialized everything to 0, but how can I store each of these data values? For example, I want [0][3] =2 and [1][2] = 3. I would like to keep track of the line on which I found that row, col, and data value. So, how can I correctly insert these values into my 2-D array?
int rowcol[8][8];
for (int i=0; i < 9; i++)
for (int j=0; j < 9; j++)
{
rowcol[i][j] =0;
}
ifstream myfile;
int nums;
myfile.open(text.c_str());
while (!myfile.eof()) {
myfile >> nums;
numbers.push_back(nums);
}
for (int i=0; i < numbers.size(); i++)
{
//Not sure what the best approach here would be and I'm not even sure if I should have done a vector...
}