initialise vector c++ code example
Example 1: initialize vector of vector c++
#include <iostream>
#include <vector>
#define M 3
#define N 4
int main()
{
int default_value = 1;
std::vector<int> v(N, default_value);
std::vector<std::vector<int>> matrix(M, v);
return 0;
}
Example 2: how to initialize vector
vector<int> vect{ 10, 20, 30 };
Example 3: c++ vector initialization
vector<int> a;
vector<int> b (5, 10);
vector<int> c (b.begin(),b.end());
vector<int> d (c);
Example 4: how to initialize a vector in c++
std::vector<type> name;