Here is some code I used in a Grid class I had for a game. It reads integers from a file and stores them in a 10 x 10 2D array. (Technically it's a vector inside a vector but it's the same syntax)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
bool Grid::LoadGrid(string filename) {
int input;
ifstream fin;
fin.open(filename.c_str());
if (!fin)
returnfalse; // file corrupted or missing
for (int i = 0; i < GRID_MAX and fin; i++)
for (int j = 0; j < GRID_MAX and fin; j++) {
fin >> input;
pos[j][i] = input;
}
returntrue;
}