Code wont compile

I'm getting an error:
 
error: declaration of âtestsâ as multidimensional array must have bounds for all dimensions except the first


I dont see how that is because I have a size declared in the second []. Here my code:
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
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

const int MAX_STUDENTS = 50, MAX_TESTS = 20;

void read_2_matrix(const string ID[], const int tests[][MAX_TESTS], int& nTests);

int main()
{
	int numTest, tests[][MAX_TESTS];
	string ID[MAX_STUDENTS];
	read_2_matrix(ID, tests, numTest);
	
	
	
	
	
	return 0;
}


void read_2_matrix(const string ID[], const int tests[][MAX_TESTS], int& nTests)
{
	ifstream ifile;
	ifile.open("test_score.txt");

    if (ifile.fail())
    {
        cout << "Failed to open input file." << endl;
        exit(1);
    }
	
	ifile >> nTests;
	
	int x = 0;
	while(ifile >> ID[x])
    {
		
		for(int i=0; i<MAX_STUDENTS; i++)
			for(int j=0; j<nTests; j++)
			
				ifile >> tests[i][j];
		x++;
	}
	
	for(int i=0; i<50; i++)
	{
		cout << ID[i] << ' ';
		cout << endl;
	}
	


	
}
Lol, declarations of that type are interpretted back to front.

int array[5] would be a pointer to the first int of five.
int array[5][10] would be a pointer to the first integer array with length 10, of five integer arrays.

Think of it as if it had parentheses around it:

(tests [] ) [MAX_TESTS];

In fact, parentheses wouldn't be illegal (nor is the whitespace); the compiler should see it the same way.
Say what?
Try the C++ Documentation and look at the Arrays page.

http://www.cplusplus.com/doc/tutorial/arrays.html
Topic archived. No new replies allowed.