多维数组
声明多维数组的基本结构如下:
int testArray[2][2]{
{11,22},
{33,44}
};
std::array<array<int, 2>,2> testArray2;
testArray2[0] = {{11,22}};
testArray2[1] = {{33,44}};
上述代码声明了一个2维数组testArray和testArray2,可以将第一个"[]"内的数字看做行数,第二个"[]"内的数字看做列数。
多维数组的声明和遍历操作如下:
#include <iostream>
#include <cstdio>
#include <string>
#include <array>
using namespace std;
int main()
{
array<int, 10> testArray{11,22,33,44,55,66,77,88,99,00};
array<int, 10> testArray2{22,33,44,55,66,77,88,99,00,11};
array<int, 10> testArray3{33,44,55,66,77,88,99,00,11,22};
array<array<int, 10>, 3> testArrayTotal;
testArrayTotal = { testArray, testArray2, testArray3 };
for (int i = 0; i < testArrayTotal.size();i++){
for (int j = 0; j < 10; j++){
cout << testArrayTotal[i][j] << "\n";
}
cout << "," << endl;
}
}