#include <iostream>
using namespace std;
int main()
{
int a[] = {1,2,4};
for(auto aa: a)
{
cout << aa << " ";
}
cout << endl;
auto beg = begin(a),eg = end(a);
while (beg!=eg)
{
cout << *beg++ << " ";
}
cout << endl;
cout << "打印二维数组" << endl;
int b[2][3] = {1,2,3,4,5,6};
//for(auto row:b)这样不行,the innermost array must be references,
//innermost是最里层的意思,但在这我总觉得row应该是最外层啊,是作者笔误,还是我理解有问题?
for (auto& row:b)
{
for (auto column: row)
{
cout << column << " ";
}
cout << endl;
}
for (auto row=begin(b);row!=end(b);++row)
{
for (auto column=begin(*row);column!=end(*row);++column)
{
cout << *column << " ";
}
cout << endl;
}
}
1 2 4
1 2 4
打印二维数组
1 2 3
4 5 6
1 2 3
4 5 6