STL: for_each
来源:互联网 发布:淘宝商品降价通知 编辑:程序博客网 时间:2024/05/17 16:11
#include <algorithm> #include <iterator> #include <iostream> #include <vector> using namespace std; class GenByTwo { public: GenByTwo (int _seed = 0):seed(_seed){} int operator() () {return seed += 2;} private: int seed; }; void operate(int &rhs) { cout << rhs << " "; rhs += 1; } int main(int argc, char* argv[]) { vector<int> v(10); generate(v.begin(), v.end(), GenByTwo(2)); for_each(v.begin(), v.end(), operate); std::cout << std::endl; //print copy(v.begin(), v.end(), ostream_iterator<int>(cout, " ")); return 0; }
4 6 8 10 12 14 16 18 20 22
5 7 9 11 13 15 17 19 21 23
#include <iostream> // std::cin, std::cout#include <iterator> // std::istream_iterator#include <string>#include <map>#include <fstream>#include <algorithm>#include <ctime>using namespace std;map<string , int> m;void print( const pair<string, int> &r){cout << r.first << " " << r.second << endl;}void record( const string &s){m[ s ] ++;}int main(){double beginTime = clock();fstream in("test.txt");istream_iterator<string> ii(in);istream_iterator<string> eos;for_each(ii,eos,record);for_each( m.begin(), m.end(), print);double endTime = clock();cout << " time: " << endTime - beginTime << " ms" << endl;return 0;}time: 66 ms
0 0
- STL for_each
- STL::for_each
- stl for_each()
- STL for_each
- STL--for_each()
- STL for_each
- STL: for_each
- STL algorithm for_each
- (STL)for_each、find_if用法
- STL for_each,find_if用法
- stl for_each某种用法
- STL::for_each用法
- STL - for_each 简单应用
- 【STL】for_each示例
- STL运算算法-for_each()
- stl for_each使用
- STL 之for_each,transform
- STL for_each 用法
- 【Java多线程与并发库】5.线程范围内共享变量的概念与作用
- Matlab Robotic Toolbox V9.10工具箱(四):常用函数
- JavaScript中的表格对象
- HDU 1242 Rescue (BFS+优先队列)
- Haar特征检测 - 人脸识别
- STL: for_each
- 前端模板的原理与实现
- 拯救白领颈椎:治疗肩周
- Spring 支持 CORS 请求踩的坑
- 关于Servlet的过滤器
- mysql 分组和获取随机记录
- Spring 使用 Quartz 任务调度定时器
- 预处理-分节4(#error 预处理,#line 预处理)
- GoogleNet的Inception_v1、Inception_v2、Inception_v3、Inception_v4(整理)