0
Q:

how to assign 2d vectors value to a 2d vector

#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; 
} 
1
// C++ code to demonstrate 2D vector 
#include <iostream> 
#include <vector> // for 2D vector 
using namespace std; 
  
int main() 
{ 
    // Initializing 2D vector "vect" with 
    // values 
    vector<vector<int> > vect{ { 1, 2, 3 }, 
                               { 4, 5, 6 }, 
                               { 7, 8, 9 } }; 
  
    // Displaying the 2D vector 
    for (int i = 0; i < vect.size(); i++) { 
        for (int j = 0; j < vect[i].size(); j++) 
            cout << vect[i][j] << " "; 
        cout << endl; 
    } 
  
    return 0; 
} 
0

New to Communities?

Join the community