c++如何处理多维数组

时间:2021-05-01 19:00:38
<strong><span style="font-size:14px;">//

#include<iostream>
#include<vector>
#include<cstddef>
using namespace std;

int main(int argc, char *argv[])
{

const size_t a=3, b=4;
int v[a][b];
//对于每一行
for (size_t i = 0; i != a; ++i)
//对于每一列
for (size_t j = 0; j != b; ++j)
{
v[i][j] = i*j;
}
//使用范围for语句打印每一个数组元素
for (auto &i:v)
for (auto &j : i)
cout << j<<' ';
//使用标准库函数begin和end
for (auto p = begin(v); p != end(v); ++p)
{
for (auto q = begin(*p); q != end(*p); ++q)
{
cout << *q<<' ';
}
}
//类型别名简化多维数组的指针 尚不支持
//using int_array int[4];
//typedef int int_array[3];

system("pause");
return 0;
}</span></strong>