Skip to content

Instantly share code, notes, and snippets.

@s1nisteR
Created May 29, 2022 17:20
Show Gist options
  • Save s1nisteR/7a32a7d506da49a3f6a5235243280006 to your computer and use it in GitHub Desktop.
Save s1nisteR/7a32a7d506da49a3f6a5235243280006 to your computer and use it in GitHub Desktop.
Initializing 2D C++ Vectors
#include <iostream>
#include <vector>
using namespace std;
int main()
{
//=========Initializing 2D vectors==================
int n, m;
//suppose some size taken, from input or otherwise
n = 4;
m = 5;
vector<vector<bool> > arr;
//===========================================================================
//===========================================================================
//MAIN PART==================================================================
arr.resize(n);
for(int i = 0; i < n; ++i)
{
arr[i].resize(m);
}
//============================================================================
//============================================================================
//============================================================================
//now we can easily access any element and store stuff inside without causing exceptions
arr[2][2] = true;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment