功能:
- 将容器搬运到另一个容器
#include<iostream> #include<vector> #include<functional> #include<algorithm> using namespace std; //遍历函数 transform class Transform { public: int operator()(int val) { return val; } }; class print1 { public: void operator()(int val) { cout << val << " "; } }; void test1() { vector<int> v; for (int i = 0; i < 10; i++) { v.push_back(i); } vector<int> vTarget; vTarget.resize(v.size()); transform(v.begin(), v.end(), vTarget.begin(),Transform()); for_each(vTarget.begin(), vTarget.end(), print1()); } int main() { test1(); return 0; }
标签:begin,遍历,val,vTarget,int,transform,C++,include From: https://www.cnblogs.com/ggbond00/p/17201080.html