1. for
typedef vector<int> Vct; Vct va; va.push_back(1); va.push_back(2); va.push_back(3); for(const int& k : va) cout << k << " "; cout << endl;
2. for_each 声明在 #include <algorithm>
template <class T> void show(const T& x) { cout << x << " "; } for_each(va.begin(),va.end(),show<int>); cout << endl;
3. copy 声明在<algorithm> ostream_iterator 在 <iterator>
#include <algorithm> #include <iterator> // for ostream_iterator<> copy(va.begin(),va.end(),ostream_iterator<int>(cout," ")); cout << endl;
原文地址:https://www.cnblogs.com/htj10/p/10886324.html
时间: 2024-10-11 05:16:42