vector<double> vec;
vec.push_back(1);
vec.push_back(6);
vec.push_back(5);
vec.push_back(4);
vec.push_back(3);
//ranged-based for(since C++11)
// C+11遍历使用新的方式
for (auto elem : vec)//pass by value
{
cout << elem << endl;
}
for (auto& elem : vec)//pass by reference
elem *= 3;
for (int i : {2, 3, 5, 7, 9, 13, 17, 19})
cout << i << ' ';
c++新型遍历方式: ranged-based for(since C++11)
最新推荐文章于 2024-05-27 11:55:34 发布