I am a novice in C++ and I am trying to create a simple static 3 Dimensional Array and then print it out in console.
Here is my current code:
#include <iostream>
using namespace std;
int main()
{
const int MAX_ROW = 2;
const int MAX_COL = 2;
const int MAX_HEIGHT = 2;
int MyArray[MAX_ROW][MAX_COL][MAX_HEIGHT] = { {1,1},
{2,10},
{3,15},
{4,20},
{5,25},
{6,30},
{7,35},
{8,40} };
for(int Row = 0; Row < MAX_ROW; ++Row)
{
for(int Col =0; Col < MAX_COL; ++Col)
{
for(int Height = 0; Height < MAX_HEIGHT; ++Height)
{
cout << "Integer["<< Row << "][" << Col << "][" << Height << "] = " << MyArray[MAX_ROW][MAX_COL][MAX_HEIGHT] << endl;
}
}
}
return 0;
}
When I compile the compiler notifies me stating "error: too many initializers for ‘int [2][2][2]"
Other questions have used pointers which I am not familiar with.
Thank you in advance!
Edit: The syntax is wrong so I have corrected it with the correct corresponding code as answered below. Now in the output of the program each array space is 32767. A full integer space instead of the assigned values. Can anybody address this in their answer? I have not changed any code except my initialisation of the array.
operator () (unsigned,unsigned,unsigned)for element access (const and non-const versions).