BuySexual
0
Q:

c++ initialize a vector

vector<vector<vector<double>>> f(3, vector<vector<double>>(4, vector<double>(5)));
2
#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;
}
2
// CPP program to create an empty vector 
// and push values one by one. 
#include <bits/stdc++.h> 
using namespace std; 
  
int main() 
{ 
    int n = 3; 
  
    // Create a vector of size n with 
    // all values as 10. 
    vector<int> vect(n, 10); 
  
    for (int x : vect) 
        cout << x << " "; 
  
    return 0; 
} 
5
std::vector<type> name;
5
#include <bits/stdc++.h> 
#include <vector> 
using namespace std; 
  
int main() 
{ 
// This vector initializes with the values: 10, 20, and 30
  vector<int> vect{ 10, 20, 30 }; 

    return 0; 
} 
2
std::vector<int*> stuff;
0
vector<int> vect{ 10, 20, 30 };
0

New to Communities?

Join the community