#include <iterator> //这里使用了标准库的begin和end
void twoDe() //P116->T3.43 范围for的二维数组
{
int a[3][4] = { 1,2,3,4,5,6,7,8,9,4,5,32 };
size_t i = 0;
for(auto &row:a)
for (auto &col : row)
{
//col = i;
//++i;
cout << col;
}
}
void twoDe1() //P116->T3.43 下标的二维数组
{
int a[3][4] = { 1,2,3,4,5,6,7,8,9,4,5,32 };
constexpr size_t row = 3, col = 4;
for(size_t i=0;i!=row;++i)
for (size_t j = 0; j != col; ++j)
{
cout << a[i][j] << " ";
//a[i][j] = 1;
}
}
void twoDe2() //P116->T3.43 指针的二维数组
{
int a[3][4] = { 1,2,3,4,5,6,7,8,9,4,5,32 };
for (auto p = std::begin(a); p != std::end(a); ++p)
{
for (auto q = std::begin(*p); q != std::end(*p); ++q)
{
cout << *q << " ";
}
cout << endl;
}
}
void twoDe3() //P116->T3.43 指针的二维数组
{
int a[3][4] = { 1,2,3,4,5,6,7,8,9,4,5,32 };
for (auto p = a; p != a+3; ++p)
{
for (auto q = *p; q != *p; ++q)
{
cout << *q << " ";
}
cout << endl;
}
}