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));
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));
2d array using vector
// CPP program
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int n = 4;
int m = 5;
/*
Create a vector containing "n"
vectors each of size "m".
*/
vector<vector<int>> vec( n , vector<int> (m));
for(int i = 0; i < n; i++)
{
for(int j = 0; j < m; j++)
{
vec[i][j] = j + i + 1;
}
}
for(int i = 0; i < n; i++)
{
for(int j = 0; j < m; j++)
{
cout << vec[i][j] << " ";
}
cout << endl;
}
return 0;
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us