Answers for "2d stl array"

C++
0

2d stl array

/*
std::array is 1-dimensional, there is no such thing as a 2-dimensional std::array.
You would simply have to use an inner std::array as the element type of an outer 
std::array, eg:
*/
#include <iostream>
#include <array>

int main(){
  std::array<std::array<int,5>,4> myarray;
  for (int i=0; i<5; i++){
    for (int j=0; j<10; j++){
      myarray[i].at(j) = j+1;    
    }
  }
}
Posted by: Guest on September-22-2021

Browse Popular Code Answers by Language