1. Using arrays are C-style coding, using vectors are C++-style coding.
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.
When you want to work with a fixed number of std::vector elements, you can use vector <int> V[].
When you want to work with a dynamic array of std::vector, you can use vector< vector<int> > V.
2.
One difference would be that although both can be initialized in the same way, e.g.
the V1 can't grow. You cannot make V1.push_back(...) as its not a vector object. Its just an array. Second one is dynamic. You can grow it as you please
the V1 can't grow. You cannot make V1.push_back(...) as its not a vector object. Its just an array. Second one is dynamic. You can grow it as you please
来自:http://stackoverflow.com/questions/28712364/difference-between-vector-int-v-and-vector-vectorint-vstackflow 网站1. Using arrays are C-style coding, using vectors are C++-style coding.Ve