dimanche 22 avril 2018

C++ reading data from txt file and putting it into 2d array

I've got a file with numbers separated by a single space and I want to put them into the 2D array. There are 200 rows of 320 numbers each. This is my code:

int data[200][320];
int i = 0;
int j = 0;

file.open("./../../../Data_PR2/data.txt", ios::in);


while (file>> data[i][j])
    {
        if (j == 319) {
            j = 0;
            i++;
        }
        else {
            j++;
        }
    }

And it kinda works, because first rows are correctly inserted but not all rows.

So what's wrong?

Aucun commentaire:

Enregistrer un commentaire