Text file to a 2D array

Hi guys, I was wondering if someone could point me to the right direction with this problem. I'm suppose to read the numbers.txt file into a 2D array and output the context of the array.
Thank you.
1 2 3 4 5
2 3 4 5 1
3 4 5 1 2
4 5 1 2 3

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
#include <fstream>
using namespace std;

int main()
{
	const int ROW = 4;
	const int COLS = 5;
	int grid[ROW][COLS];
	ifstream infile;
	infile.open("numbers.txt");
	if(infile.fail())
	{
		cout << "Sorry, could not open input file!\n";
		exit(1);
	}
	for(int i=0; i < ROW; i++)
	{
		for(int j=0; i < COLS; j++)
		{
		   infile >> grid[i][j];
		}
	}
	
	infile.close();
}
Last edited on
Topic archived. No new replies allowed.