代码
#include<iostream> #include<memory> #include<string> #include<vector> #include<algorithm> using namespace std; const int NUM = 5; void show(double d) { cout << d << " "; } int main(void) { vector<double> scores = { 11,23 }; //第一种遍历方式 for (auto pd = scores.begin(); pd != scores.end(); pd++) { cout << *pd << " "; } cout << endl; double temp = 5; scores.push_back(temp); //第二种遍历方式 for_each(scores.begin(), scores.end(), show); cout << endl; //第三种遍历方式 for (auto score : scores) { cout << score << " "; } cin.get(); return 0; }
运行结果