Answers for "vector size initialization c++"

C++
2

c++ initialize vector of vector with size

vector<vector<int>> v(10, vector<int>(10));
Posted by: Guest on May-24-2021
1

declare vectors c++

vector<int> vec;
//Creates an empty (size 0) vector
 

vector<int> vec(4);
//Creates a vector with 4 elements.

/*Each element is initialised to zero.
If this were a vector of strings, each
string would be empty. */

vector<int> vec(4, 42);

/*Creates a vector with 4 elements.
Each element is initialised to 42. */


vector<int> vec(4, 42);
vector<int> vec2(vec);

/*The second line creates a new vector, copying each element from the
vec into vec2. */
Posted by: Guest on May-25-2020
-1

c++ vector initialize size

vector<Entry> array(1000);//size of 1000
Posted by: Guest on February-04-2021

Browse Popular Code Answers by Language