+ 2

How to declare a 2d array with <array> header

Im messing around with the <array> header array at the moment and wondered how one can declare a 2d array with it. I googled it too but only got results for normal arrays. I tried: array<array<int, 3>, 8> arr1; Which I thought should have worked, since the first argument is type and the second how many you want to store, but that didn't work. Thanks in advance for the help ^^

14th Apr 2019, 1:39 PM
Daniel Möhring
Daniel Möhring - avatar
1 ответ
+ 1
Works like that. I just forgot the colon after the first argument... Leaving this post tho for others having this question. Arrays aren't initialized with separated {} like in normal arrays. So you initialize like that: array< array <int, 3>, 3> arr1 = {0,1,2,3,4,5,6,7,8}; instead of: arr[3][3] ={{0,1,2} ,{3,4,5} ,{6,7,8}};
14th Apr 2019, 2:46 PM
Daniel Möhring
Daniel Möhring - avatar