【发布时间】:2018-04-20 23:41:04
【问题描述】:
如何使用std::array 初始化数组数组?
我的解决方案是
array<array<int, sze>, sze> arcpp { 0, 1, 2, 3 , 4, 5, 6, 7, 8, 9, 10, 11 ,12, 13, 14, 15 };
for (auto i = 0; i < sze; i++) {
cout << "\n";
for (auto j = 0; j < sze; j++) {
cout << "\t" << arcpp[i][j];
}
}
但我想要这样的东西:
int matrix[][sze] = {
{0, 1, 2, 3},
{4, 5, 6, 7},
{8, 9, 10, 11},
{12, 13, 14, 15}
};
【问题讨论】:
-
出于兴趣,您为什么要这样做?你不能使用一维数组和像
i * rows + j这样的索引吗?
标签: c++ arrays c++11 matrix initialization