STL - for_each 简单应用

来源:互联网 发布:淘宝卖家生存现状 编辑:程序博客网 时间:2024/05/19 13:21

http://www.cplusplus.com/reference/algorithm/for_each/


#include <iostream>#include <list>#include <algorithm>using namespace std;template <class T>void print(T  &t){cout<<t;}template <class T>class  Print{public:void operator()(T&t)   {   cout<<t;   }}; int main(){list <int>  L;for (int i=1;i <=7;i++)   L.push_front(i);for_each(L.begin(),L.end(),print<int> );cout<<endl;for_each(L.begin(),L.end(),Print<int>() );return 1;}



原创粉丝点击