Horje
create a 2d vector in c++ Code Example
2d vector c++ declaration
vector< vector<int>> a(rows, vector<int> (cols));
how to make a 2d vector in c++
// Create a vector containing n 
//vectors of size m, all u=initialized with 0
vector<vector<int> > vec( n , vector<int> (m, 0));  
size of a matrix using vector c++
// finding size of a square matrix
myVector[0].size();
initialise 2d vector in c++
// Initializing 2D vector "vect" with 
// values 
vector<vector<int> > vect{ { 1, 2, 3 }, 
                           { 4, 5, 6 }, 
                           { 7, 8, 9 } }; 
create a 2d vector in c++
// CPP program
#include <iostream>
#include <vector>
using namespace std;
int main()
{
    int n = 3;
    int m = 4;
 
    /*
    We create a 2D vector containing "n"
    elements each having the value "vector<int> (m, 0)".
    "vector<int> (m, 0)" means a vector having "m"
    elements each of value "0".
    Here these elements are vectors.
    */
    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<< endl;
    }
     
    return 0;
}




Cpp

Related
how can I convert each and every element of string push into set in c++? Code Example how can I convert each and every element of string push into set in c++? Code Example
declare static table filled cpp Code Example declare static table filled cpp Code Example
2d array Code Example 2d array Code Example
c++ loop through string Code Example c++ loop through string Code Example
minimum no of jump required to reach end of arry Code Example minimum no of jump required to reach end of arry Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
8