Answers for "vector initialize vector with values"

C++
7

initialize vector of vector c++

#include <iostream>
#include <vector>
 
#define M 3
#define N 4
 
int main()
{
  // specify default value to fill the vector elements
  int default_value = 1;
  // first initialize a vector of ints with given default value
  std::vector<int> v(N, default_value);
  // Use above vector to initialize the two-dimensional vector
  std::vector<std::vector<int>> matrix(M, v);
  
  return 0;
}
Posted by: Guest on April-26-2020
0

vector with initial value

// For declaring 
vector v(size, default_value);

// For Vector with a specific default value
// here 5 is the size of the vector
// and  10 is the default value
vector v1(5, 10);
Posted by: Guest on March-18-2021

Browse Popular Code Answers by Language