Created
May 29, 2022 17:20
-
-
Save s1nisteR/7a32a7d506da49a3f6a5235243280006 to your computer and use it in GitHub Desktop.
Initializing 2D C++ Vectors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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