Q:

The simplest way of defining 2_dimensional array in c++

I need an 2_dimensional array in c++ which gets the dimension from user. How can I define an int 2_dimensional array in c++? I found something that define a 1_dimensional array then define other array in each element. like this:
int **ary = new int[sizeY];
for (int i = 0; i < sizeY; i++)
    ary[i] = new int[sizeX]; 

Is there any other simple way?

A:

std::vector<std::vector<int>> myarray(sizeY, std::vector<int>(sizeX));

A:

You should use a vector of a vector to do a 2 dimension array in c++
std::vector< std::vector<int> > myarray;

for(int i = 0; i < sizeY; i++)
{
     myarray.push_back(std::vector<int>());
     for(int j = 0; j < sizeX; j++)
     {
          myarray[i].push_back(0);
     }
}

And you can access your element with  myarray[y][x]

