vector
and vector< vector
both are 2D array.
But what is the differenc
vector
is an array of vectors.
vector< vector
is a vector of vectors.
Quoting cplusplus.com ,
Vectors are sequence containers representing arrays that can change in size.
Just like arrays, vectors use contiguous storage locations for their elements, which means that their elements can also be accessed using offsets on regular pointers to its elements, and just as efficiently as in arrays. But unlike arrays, their size can change dynamically, with their storage being handled automatically by the container.
TL;DR:
When you want to work with a fixed number of std::vector
elements, you can use vector
.
When you want to work with a dynamic array of std::vector
, you can use vector< vector
.