一、数组
int array[] = {1,2,3,4,5};
for(auto &x : array) {
std::cout << x << std::endl;
}
二、容器
std::vector<int> arr(5, 100);
for(std::vector<int>::iterator i = arr.begin(); i != arr.end(); ++i) {
std::cout << *i << std::endl;
}
// 变成
for(auto i = arr.begin(); i != arr.end(); ++i) {
std::cout << *i << std::endl;
}