Quick actions

cmd+k|ctrl+k

Navigation

Languages

Vector 2D

Snippet info

Language

Cpp

Visibility

public

Author

estikurnia

Created

2019-09-21T23:07:58Z

Updated

2019-09-22T06:26:51Z

//LEARN VECTOR
//https://www.geeksforgeeks.org/2d-vector-in-cpp-with-user-defined-size/

#include <iostream> 
#include <vector> // for 2D vector 
using namespace std; 
  
int main() 
{ 
    // Initializing 2D vector "vect" with 
    // values 
    vector<vector<int> > vect{ { 1, 2 }, 
                               { 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 << "vect.size(): " << vect.size() << endl;     //num of rows
            //cout << "vect[i].size(): " << vect[i].size() << endl;  //num of column
        }
            
        cout << endl; 
    } 

  
    return 0; 
} 
INFO