Answers for "building a 2D array c++"

C++
1

how to create 2d array using vector in c++

vector<vector<int>> vec(N, vector<int> (M, INT_MAX));

Explanation::
vector<vector<int>> -- will take the formed container
N -- Think like row of 2d Matrix
vector<int> (M, INT_MAX) -- In each row, there is again a vector associated with it, 
that will formed 2d array.
Posted by: Guest on July-13-2021
-3

initialize 2d array c++

#include <array>
2 #include <iostream>
3
4 using namespace std;
5
6 //remember const!
7 const int ROWS = 2;
8 const int COLS = 3;


int main(){
 array<array<int, COLS>, ROWS> matrix = {
 1, 2, 3,
 4, 5, 6
 };
  
  
  return 0;
}
Posted by: Guest on May-30-2020

Browse Popular Code Answers by Language