Lars Mekes
3
Q:

2d vector in cpp constructor

#include<bits/stdc++.h> 
using namespace std; 
  
int main(){ 
    int n = 3; 
    int m = 4; 
  
    // Create a vector containing n 
    //vectors of size m.  
    vector<vector<int> > vec( n , vector<int> (m, 0));  
  
    for (int i = 0; i < n; i++) { 
        for (int j = 0; j < m; j++){ 
            cout<< vec[i][j]<< " "; 
        } 
        cout<< "\n"; 
    } 
  
return 0; 
} 
0
// Create a vector containing n 
//vectors of size m, all u=initialized with 0
vector<vector<int> > vec( n , vector<int> (m, 0));  
4

New to Communities?

Join the community