reading array from file

I'm trying to read a file with 2 rows and 6 columns of integer into a two-dimensional array. I'm not really sure how that would work... could someone give me an idea of how to do it, or an example? Thanks.


i want to read multiple array a[2][6] from file but i cant it.

it is a test file.

35 67 58 79 90 70
78 90 98 58 76 100

how can i read this array from file?

Last edited on
i couldnt find it there :S
It's the text file part. Here's a quick and dirty example:

1
2
3
4
5
6
7
8
9
10
11
12
const int x = 2;
const int y = 6;

std::ifstream ifs("file.txt");
int a[x][y];
for(int i = 0; i < x; ++i)
{
    for(int j = 0; i < y; ++j)
    {
        ifs >> a[i][j];
    }
}

I didn't do any error checking, so beware. I'd also use a std::vector instead of the raw array.
Last edited on
thank you:)
Topic archived. No new replies allowed.