标签:
这简化了一种常见的循环任务:对数组或容器类,如vector和array,的每个元素执行相同的操作。
1 double prices[5] = {4.99, 10.99, 6.87, 7.99, 8.49}; 2 3 for (double x : prices) 4 5 std::cout<< x << std::endl; 6 7 for (double &x : prices) 8 9 x = x *0.80; 10 11 for (int x: {3, 5, 2, 8, 6}) 12 13 std::cout << x <<" "; 14 15 std::cout << ‘\n‘;
标签:
原文地址:http://www.cnblogs.com/codetravel/p/4534562.html