#include <iostream>
#include <fstream>
usingnamespace std;
int main()
{
constint x = 4;
constint y = 3;
constint z = 32;
char myArray[x][y][z];
ifstream fin("c:\\test\\arr_data.txt");
for ( int i = 0; i < x; i++ )
{
for ( int j = 0; j < y; j++ )
{
fin >> myArray[i][j];
}
}
for ( int i = 0; i < x; i++ )
{
for ( int j = 0; j < y; j++ )
{
cout << "myArray[" << i << "][" << j << "] = " << myArray[i][j] << endl;
}
}
return 0;
}
Reading this file in (arr_data.txt)
one two three
four five six
seven eight nine
ten eleven twelve
It outputs:
1 2 3 4 5 6 7 8 9 10 11 12
myArray[0][0] = one
myArray[0][1] = two
myArray[0][2] = three
myArray[1][0] = four
myArray[1][1] = five
myArray[1][2] = six
myArray[2][0] = seven
myArray[2][1] = eight
myArray[2][2] = nine
myArray[3][0] = ten
myArray[3][1] = eleven
myArray[3][2] = twelve