const size_t row = 3, col = 4;
int ia[row][col] = {{1}, {2}, {3}};
//下标for循环
for(size_t i = 0; i != row; ++i)
{
for(size_t j = 0; j != col; ++j)
cout << ia[i][j] << " ";
cout << endl;
}
//范围for循环
for(int (&rows)[col] : ia)
{
for(int cols : rows)
cout << cols <<" ";
cout << endl;
}
//指针for循环
for(int (*p)[col] = ia; p != ia + row; ++p)
{
for(int *q = *p; q != *p +col; ++q)
cout << *q << " ";
cout << endl;
}
//迭代器for循环
for(int (*p)[col] = begin(ia); p != end(ia); ++p)
{
for(int *q = begin(*p); q != end(*p); ++q)
cout << *q << " ";
cout << endl;
}
更好的方法是用auto或decltype,显式的指定类型更方便理解遍历的过程