Assuming that
N
is some kind of integer,
- there is an
#include <vector>
somewhere,
- there is either a
using namespace std;
or a using std::vector;
somewhere...
This is the declaration of an object v
, of type std::vector< int >
, initialized to hold N
objects (of type int
), which are default-initialized (i.e., indeterminate, since int
is a POD type for which no default initialization is defined).
Documentation of vector constructors -- this one is case (2).
Spiral rule -- which needs some adapting to C++ but is still a good start.
It is not "a dynamic array line vector v
", it is a vector.
And no, it is not the same as vector v[N]
(which would not even compile). It is also not the same as vector<int> v[N]
-- that would be an array of N
different vector<int>
objects.
Now if it is the first one then what is vector< vector< int > > V(N)
?
Since it's not the first one, do I still have to answer this? :-D
vector< vector< int > > V(N);
That is the declaration of an object V
of type vector< vector< int > >
, i.e. "vector of int-vectors", initialized to hold N
default-initialized objects...
...i.e., a vector holding N
objects of vector< int >
-- which are, in turn, empty (because "empty" is what default-initialized vectors are).
C++ has...
- The array (
int v[N];
), which works exactly like the C array.
- The std::vector (
std::vector< int > v;
), which is dynamic in size.
- The std::array (
std::array< int, N >;
), which is static in size like the C array, but does offer some of the niceties of std::vector
.
You need to be exact about what you are referring to. These are quite distinct types with a distinct feature set.
UPDATE:
With your latest couple of edits, it became clear that your real question is:
What is a vector
?
It's a C++ class template implementing a container that can hold contiguous elements of a given type (like a C array), but is dynamically-sized (unlike a C array).
See the documentation.
Generally speaking, you don't use C arrays in C++ code anymore, except for some really special cases. You use std::string
for strings, and std::vector
for (almost) everything else you used arrays for in C.