Reputation: 1
So I need to be able to read integers from a file into a two dimensional array. The numbers are sorted as follows:
3 3 4 5
6 3 5 6 7 8 9
and so on and so forth.
My issue is I'm not sure how to start because the first number in each row indicates the amount of numbers that are going to be read into array[i][j] where j would equal either 3 or 6. I also don't know how how many rows are going to be in the file to be tested later.
Upvotes: 0
Views: 81
Reputation: 21
As others pointed out you really should use std::vector for this. But if it have to be an array you could either store everything into a vector anyway and copy the content of that vector into an new array afterwards. Or you read the file line by line until the end such that you know the number of rows and then you can allocate and fill an array.
And for the size of the second dimension of this array: it should always be 7, except each and every row starts with 3 (where the size would be 4).
Upvotes: 2