getline with ints C++

Posted by Mdjon26 on Stack Overflow See other posts from Stack Overflow or by Mdjon26
Published on 2013-10-30T15:44:48Z Indexed on 2013/10/30 15:53 UTC
Read the original article Hit count: 136

Filed under:
|

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...

}

© Stack Overflow or respective owner

Related posts about c++

Related posts about for-loop