Files into arrays into tables

Its suppose to make a matrix(table) with the numbers from a file. But I don't know how to store the numbers from a file into a table array. I've tried looking it up and that is the method that I currently tried to do but it just reported errors. Sadly I have to use this code, so there is no way for me to just rewrite it, its part of an assignment we are working on. Any help is appreciated.

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Program TwoDim manipulates a two-dimensional array variable.
#include <iostream>
#include <fstream> 
#include <string>
using namespace std;

const int ROW_MAX = 8;
const int COL_MAX = 10;
typedef int ItemType;
typedef ItemType Table[ROW_MAX][COL_MAX];
void getData(ifstream&, Table, int&, int&); // Reads values and stores them in the table.
void printTable(ofstream&, const Table, int, int); // Write values in the table to a file.
int main()
{
	Table table;
	int rowsUsed;
	int colsUsed;
	ifstream dataIn;
	ofstream dataOut;
	int index = 0;
	dataIn.open("twod.txt");
	dataOut.open("twod.out");
	string line;
	getData(dataIn, table, rowsUsed, colsUsed);
	printTable(dataOut, table, rowsUsed, colsUsed);
	const int MAX = 80; //array size
	int numbers[MAX]; //array numbers with 80 limit

	if (dataIn.is_open())
	{
		
			ifstream data;

			//ItemType item;
			data >> rowsUsed >> colsUsed;
			for (int row = 0; row < rowsUsed; row++)
			{
				for (int col = 0; col < colsUsed; col++)
				{
					while (dataIn >> numbers[col])
					{

						while (!dataIn.eof())
						{
							getline(dataIn, line);
							numbers[MAX] << line;
						}
					}


					// FILL IN Code to read the next value from input file and store it in array table. 
				}
			}

		
	}
		//****************************************************
		void printTable(ofstream& data, const Table table, int rowsUsed, int colsUsed);
		// Pre: table contains valid data. 
		// Post: Values in array table have been sent to a file by row, 
		// one row per line. 
		{
			cout << table;
		}
	

	return 0; 
}
You access the elements of a 2d array like this:
1
2
Table table;
table[0][0] = 1; // sets the lement at row 0 and col 0 to 1; 
Topic archived. No new replies allowed.