vector <int> V[]
和 vector< vector<int> > V
两者都是二维数组。
但是它们之间的区别是什么?我们在哪里使用它们呢?请简要说明。
最佳答案
vector<int> V[]
是一个 vector 数组。
vector< vector<int> > V
是一个 vector 的 vector 。
使用数组是C风格的编码,使用 vector 是C++风格的编码。
引用 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:
当您想使用固定数字 std::vector
时元素,您可以使用 vector <int> V[]
.
当您想要使用std::vector
的动态数组 时, 你可以使用 vector< vector<int> > V
.
关于c++ - vector <int> V[]和 vector <vector<int>> V的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28712364/