There are several ways to define a 2D array in C++ and STL without memory manipulation, and the following codes illustrate two different methods:
int main ()
{
There are a lot of trade-offs here.
If you declare a C-style 2D array int array[height][width], then you really get a single contiguous block of memory. The compiler converts indexes to their 1D address
array[row][col] == *(array + row * width + col)
If you use a vector of vectors, then each row is allocated separately. The outer vector stores pointers to the inner vectors. Indexing becomes an indirection followed by an addition:
array[row][col] == *(*(array + row) + col)
vector).If performance is truly important, you need to test both and figure out which is faster on your data.