南通建设企业网站,网站设计的提案,网站建设seo视频,阿里云主机怎么搭建wordpress函数对象
概念 重载函数调用运算符的类实例化的对象 , 就叫函数对象 . 又名仿函数 函数对象和 () 触发重载函数调用运算符的执行。 作用 : 为算法提供策略。 示例
class MyPrint
{
public:void operator()(char *s){coutsendl;}
};
void test01()
{MyPrint…函数对象
概念 重载函数调用运算符的类实例化的对象 , 就叫函数对象 . 又名仿函数 函数对象和 () 触发重载函数调用运算符的执行。 作用 : 为算法提供策略。 示例
class MyPrint
{
public:void operator()(char *s){coutsendl;}
};
void test01()
{MyPrint ob1;ob1(hello world);MyPrint()(hello world);
}
谓词
概念 返回值为 bool 类型的普通函数 或 仿函数 都叫谓词。 有一个参数 叫 一元谓词。 有二个参数 叫 二元谓词。 示例 1, 使用一元谓词查找大于 30 的数 #include iostream
#include vector
#include algorithm
using namespace std;
class GreaterThan30
{
public:bool operator()(int val){return val30;}
};bool greaterThan30(int val){return val30;}void test02(){vectorint v1;v1.push_back(10);v1.push_back(20);v1.push_back(30);v1.push_back(40);v1.push_back(50);//寻找大于30的数vectorint::iterator ret;//仿函数提供策略 需要函数对象//ret find_if(v1.begin(), v1.end(), GreaterThan30() );//普通函数提供策略ret find_if(v1.begin(), v1.end(), greaterThan30 );if(ret ! v1.end()){cout找到的值:*retendl;}} 2.使用二元谓词实现排序 void myPrintInt(int val)
{coutval ;
}
class MyGreater
{
public:bool operator()(int v1, int v2){return v1v2;}
};bool myGreater(int v1, int v2){return v1v2;}void test03(){vectorint v1;v1.push_back(30);v1.push_back(20);v1.push_back(10);v1.push_back(40);v1.push_back(50);for_each(v1.begin(),v1.end(), myPrintInt);coutendl;//更改排序策略//sort(v1.begin(), v1.end(), MyGreater());sort(v1.begin(), v1.end(), myGreater);for_each(v1.begin(),v1.end(), myPrintInt);coutendl;
} 内建函数对象
概念 STL提供的函数对象 算法类函数对象
语法 template class T T plus T // 加法仿函数 template class T T minus T // 减法仿函数 template class T T multiplies T // 乘法仿函数 template class T T divides T // 除法仿函数 template class T T modulus T // 取模 ( 取余 ) 仿函数 template class T T negate T // 取反仿函数 注意 :6 个算数类函数对象 , 除了 negate 是一元运算 , 其他都是二元运算 示例 1, 基本使用 #includealgorithm
void test04()
{
plusint pl;int num01 pl(10,20);cout num01 num01 endl;int num02 plusint()(1,20);cout num02 num02 endl;int num03 minusint()(1,20);cout num03 num03 endl;int num04 multipliesint()(1,20);cout num04 num04 endl;int num05 dividesint()(20,5);cout num05 num05 endl;int num06 modulusint()(5,3);cout num06 num06 endl;int num07 negateint()(10);cout num07 num07 endl;
} 2, 本月工资所有员工加 2000 奖金 class Staff{
friend void printStaff(Staff s);string name;double money;
public:Staff(){}Staff(string name,double money){this-name name;this-money money;}
};
void printStaff(Staff s)
{double money plusdouble()(s.money,2000);cout s.name 本月工资为: money endl;
}
void test05()
{vectorStaff staffs;staffs.push_back(Staff(张三,3100));staffs.push_back(Staff(李四,3000));staffs.push_back(Staff(王五,3200));for_each(staffs.begin(),staffs.end(),printStaff);
} 关系运算类函数对象
语法 template class T bool equal_to T // 等于 template class T bool not_equal_to T // 不等于 template class T bool greater T // 大于 template class T bool greater_equal T // 大于等于 template class T bool less T // 小于 template class T bool less_equal T // 小于等 注意 :6 个关系运算类函数对象 , 每一种都是二元谓词 示例 1, 基本使用 void test06 () { cout 10 20 ? equal_to int ()( 10 , 20 ) endl ; cout 20 20 ? equal_to int ()( 20 , 20 ) endl ; cout 10 ! 20 ? not_equal_to int ()( 10 , 20 ) endl ; cout 10 20 ? greater int ()( 10 , 20 ) endl ; cout 10 20 ? greater_equal int ()( 10 , 20 ) endl ; cout 10 20 ? less int ()( 10 , 20 ) endl ; cout 10 20 ? less_equal int ()( 10 , 20 ) endl ; } 2, 排序 void print ( int v ) { cout v ; } void test07 () { vector int nums ; nums . push_back ( 14 ); nums . push_back ( 5 ); nums . push_back ( 7 ); nums . push_back ( 3 ); nums . push_back ( 9 ); for_each ( nums . begin (), nums . end (), print ); cout endl ; sort ( nums . begin (), nums . end (), greater int ()); for_each ( nums . begin (), nums . end (), print ); cout endl ; } 逻辑运算类函数对象 语法 template class T bool logical_and T // 逻辑与 template class T bool logical_or T // 逻辑或 template class T bool logical_not T // 逻辑非 注意 :3 个逻辑运算类运算函数 ,not 为一元谓词其余为二元谓词。 适配器 bind2nd 将绑定的数据放置第二个参数位置 bind1st 将绑定的数据放置第一个参数位置 函数对象适配器
特点 将函数对象作为适配器 步骤 1, 创建一个类 , 使其公共继承 binary_function, 并进行参数萃取 参数萃取 : 模板中第一个类型为重载函数调用运算符第一个参数的数据类型 模板中第二个类型为重载函数调用运算符第二个参数的数据类型 模板中第二个类型为重载函数调用运算符返回值的数据类型 2,const 修饰重载函数调用运算符 3, 使用 bindxxx 绑定函数对象与适配器 示例 1, 本月工资所有员工加 2000 奖金 class Staff{
string name;
double money;
public:Staff(){}Staff(string name,double money){this-name name;this-money money;}double getMoney(){return money;}
};
class PlusMoney:public binary_functionStaff,double,void{
public:void operator()(Staff s,double d) const{double money s.getMoney() d;cout money ;}
};
void test08()
{vectorStaff staffs;staffs.push_back(Staff(张三,3100));staffs.push_back(Staff(李四,3000));staffs.push_back(Staff(王五,3200));for_each(staffs.begin(),staffs.end(),bind2nd(PlusMoney(),2000.0));
} 函数指针适配器 特点 将普通函数地址作为适配器 ptr_fun( 函数名 ) 示例 void myPrintInt2(int val,int tmp)
{coutval tmpendl;
}
void test09()
{vectorint v1;v1.push_back(30);v1.push_back(20);v1.push_back(10);v1.push_back(40);v1.push_back(50);//1、bind2nd或bind1st 进行参数绑定for_each(v1.begin(),v1.end(), bind1st(ptr_fun(myPrintInt2),300) );coutendl;
} 成员函数适配器 特点 将成员函数地址作为适配器 mem_fun_ref( 类名 :: 函数名 ) 示例 class Data
{
private:int a;
public:Data(){}Data(int a):a(a){}void showData(){coutthis-aendl;}
};
void test10()
{vectorData v1;v1.push_back(Data(10));v1.push_back(Data(20));v1.push_back(Data(30));v1.push_back(Data(40));v1.push_back(Data(50));for_each(v1.begin(), v1.end(), mem_fun_ref(Data::showData));
} 取反适配器 not1 一元函数对象取反 not2 二元函数对象取反 示例 void test11()
{vectorint v1;v1.push_back(10);v1.push_back(20);v1.push_back(30);v1.push_back(40);v1.push_back(50);vectorint::iterator ret;ret find_if(v1.begin(), v1.end(), not1(bind2nd(greaterint(), 30))
);
if(ret ! v1.end())
{cout找到的结果:*retendl;
}
//lambda表达式
for_each(v1.begin(), v1.end(), [](int val){coutval ;
} );coutendl;sort(v1.begin(), v1.end(),not2(greaterint()) );for_each(v1.begin(), v1.end(), [](int val){coutval ;
});coutendl;
} 算法
1.遍历 for_each 作用 : 遍历 语法 /* 遍历算法 遍历容器元素 param beg 开始迭代器 param end 结束迭代器 param _callback 函数回调或者函数对象 return 函数对象 */ for_each ( iterator beg , iterator end , _callback ); 示例1.普通使用 void print01(int v)
{cout v endl;
}
void test01()
{vectorint nums;nums.push_back(10);nums.push_back(30);nums.push_back(40);nums.push_back(20);nums.push_back(50);for_each(nums.begin(),nums.end(),print01);
} 示例 2:for-each 的返回值 class Data{
public:int count;Data(){count 0;}void operator()(int v){cout v ;count;}
};
void test02()
{listint nums;nums.push_back(1);nums.push_back(5);nums.push_back(2);nums.push_back(4);nums.push_back(3);cout 数据:;Data d for_each(nums.begin(),nums.end(),Data());cout endl;cout count: d.count endl;
} 示例 3 class Person{
private:string name;int age;
public:Person(){}Person(string name,int age):name(name),age(age){}~Person(){}void showInfo(){cout name age endl;}
};
void test03()
{vectorPerson ps;Person p1(张三,23);Person p2(李四,29);Person p3(王五,19);ps.push_back(p1);ps.push_back(p2);ps.push_back(p3);for_each(ps.begin(),ps.end(),mem_fun_ref(Person::showInfo));
} transform 作用搬运 语法 /* transform 算法 将指定容器区间元素搬运到另一容器中 注意 :transform 不会给目标容器分配内存所以需要我们提前分配好内存 param beg1 源容器开始迭代器 param end1 源容器结束迭代器 param beg2 目标容器开始迭代器 param _cakkback 回调函数或者函数对象 return 返回目标容器迭代器 */ transform(iterator beg1, iterator end1, iterator beg2, _callbakc); /* transform 算法 将指定容器区间元素搬运到另一容器中 注意 :transform 不会给目标容器分配内存所以需要我们提前分配好内存 param beg1 源容器 1 开始迭代器 param end1 源容器 1 结束迭代器 param beg2 源容器 2 开始迭代器 param result 结果 param _cakkback 回调函数或者函数对象 return 返回目标容器迭代器 */ transform(iterator beg1, iterator end1, iterator beg2,iterator result,_callbakc); 示例 1 int setData(int a){
return a100;
}int setData2(int a,int x){return ax;
}
void test04()
{vectorint vs;srand(time(NULL));for(int i 0; i 10; i){vs.push_back(rand() % 100);
}
for_each(vs.begin(),vs.end(),print01);cout endl;listint ls;ls.resize(vs.size());transform(vs.begin(),vs.end(),ls.begin(),setData);for_each(ls.begin(),ls.end(),print01);cout endl;listint ls2;ls2.resize(vs.size());transform(vs.begin(),vs.end(),ls2.begin(),bind2nd(ptr_fun(setData2),10));for_each(ls2.begin(),ls2.end(),print01);cout endl;
} 示例 2: 将容器 1 和容器 2 中的元素相加放入到第三个容器中 class Add{
public:
int operator()(int a,int b)
{
return a b;
}
};
void test05()
{
vectorint vs01;
srand(time(NULL));
for(int i 0; i 10; i)
{
vs01.push_back(rand() % 100);
}
for_each(vs01.begin(),vs01.end(),print01);
cout endl;
vectorint vs02;
for(int i 0; i 10; i)
{
vs02.push_back(rand() % 100);
}
for_each(vs02.begin(),vs02.end(),print01);
cout endl;
vectorint vs03;
vs03.resize(vs01.size());
transform(vs01.begin(),vs01.end(),vs02.begin(),vs03.begin(),Add());
for_each(vs03.begin(),vs03.end(),print01);
cout endl;
} 2.查找算法 find 作用 : 寻找 语法 /* find 算法 查找元素 param beg 容器开始迭代器 param end 容器结束迭代器 param value 查找的元素 return 返回查找到元素对应的迭代器 */ find(iterator beg, iterator end, value) 示例 void test01()
{
vectorint vs;
vs.push_back(12);
vs.push_back(15);
vs.push_back(11);
vs.push_back(13);
vs.push_back(14);
vectorint::iterator it find(vs.begin(),vs.end(),13);
if(it ! vs.end())
{
cout 找到了 endl;
}
else{
cout 不存在 endl;
}
} find_if 作用 : 条件查找 语法 /* param beg 容器开始迭代器 param end 容器结束迭代器 param callback 回调函数或者谓词 ( 返回 bool 类型的函数对象 ) return 返回查找到元素对应的迭代器 */ find_if(iterator beg, iterator end, _callback) 示例 bool myIf(int x)
{
return x 13;
}
void test02()
{
vectorint vs;
vs.push_back(12);
vs.push_back(15);
vs.push_back(11);
vs.push_back(13);
vs.push_back(14);
vectorint::iterator it find_if(vs.begin(),vs.end(),myIf);
cout *it endl;
} adjacent_find 作用 : 查找相邻重复元素 语法 /** *adjacent_find 算法 查找相邻重复元素 *param beg 容器开始迭代器 *param end 容器结束迭代器 *param _callback 回调函数或者谓词 ( 返回 bool 类型的函数对象 ) *return 返回相邻元素的第一个位置的迭代器 **/ adjacent_find(iterator beg, iterator end, _callback); 10 20 30 30 40 示例 void test03()
{
vectorint vs;
vs.push_back(12);
vs.push_back(15);
vs.push_back(11);
vs.push_back(11);
vs.push_back(13);
vectorint::iterator it adjacent_find(vs.begin(),vs.end());
cout *it endl;
} binary_search 作用 : 二分查找 语法 /*
注意: 在无序序列中不可用
param beg 容器开始迭代器
param end 容器结束迭代器
param value 查找的元素
return bool 查找返回 true 否则 false
*/
bool binary_search(iterator beg, iterator end, value); 示例 void test04()
{
vectorint vs;
vs.push_back(1);
vs.push_back(3);
vs.push_back(5);
vs.push_back(7);
vs.push_back(9);
bool b binary_search(vs.begin(),vs.end(),7);
if(b){
cout 存在 endl;
}else{
cout 不存在 endl;
}
} count 作用 : 统计 语法 /* param beg 容器开始迭代器 param end 容器结束迭代器 param value 回调函数或者谓词 ( 返回 bool 类型的函数对象 ) return int 返回元素个数 */ count(iterator beg, iterator end, value); 示例 #include set
void test05()
{
multisetint s;
s.insert(1);
s.insert(2);
s.insert(2);
s.insert(3);
s.insert(5);
int num count(s.begin(),s.end(),2);
cout num endl;
} count_if 作用 : 条件统计 语法 /* param beg 容器开始迭代器 param end 容器结束迭代器 param callback 回调函数或者谓词 ( 返回 bool 类型的函数对象 ) return int 返回元素个数 */ count_if(iterator beg, iterator end, _callback) 示例 void test06()
{
multisetint s;
s.insert(1);
s.insert(2);
s.insert(2);
s.insert(3);
s.insert(5);
//统计容器中大于2的数
int num count_if(s.begin(),s.end(),bind2nd(greaterint(),2));
cout num endl;
//统计容器中小于2的数
int num02 count_if(s.begin(),s.end(),bind2nd(lessint(),2));
cout num02 endl;
} 3.排序算法 merge 作用 : 合并 语法 /* 注意 : 两个容器必须是有序的 param beg1 容器 1 开始迭代器 param end1 容器 1 结束迭代器 param beg2 容器 2 开始迭代器 param end2 容器 2 结束迭代器 param dest 目标容器开始迭代器 */ merge(iterator beg1, iterator end1, iterator beg2, iterator end2, iterator dest) 示例 void test01()
{
vectorint v1;
v1.push_back(1);
v1.push_back(3);
v1.push_back(5);
vectorint v2;
v2.push_back(2);
v2.push_back(4);
v2.push_back(6);
vectorint v3;
v3.resize(v1.size() v2.size());
merge(v1.begin(),v1.end(),v2.begin(),v2.end(),v3.begin());
for_each(v3.begin(),v3.end(),[](int x){
cout x ;
});
cout endl;
} sort 作用 : 排序 语法 /* param beg 容器 1 开始迭代器 param end 容器 1 结束迭代器 param _callback 回调函数或者谓词 ( 返回 bool 类型的函数对象 ) */ sort(iterator beg, iterator end, _callback) 示例 void test02()
{
vectorint vs;
vs.push_back(10);
vs.push_back(13);
vs.push_back(9);
vs.push_back(4);
vs.push_back(18);
for_each(vs.begin(),vs.end(),[](int x){
cout x ;
});
cout endl;
//默认从小到大
sort(vs.begin(),vs.end());
for_each(vs.begin(),vs.end(),[](int x){
cout x ;
});
cout endl;
sort(vs.begin(),vs.end(),[](int x,int y){
return x y;
});
for_each(vs.begin(),vs.end(),[](int x){
cout x ;
});
cout endl;
} 示例2 class Person{
private:
string name;
int age;
public:
Person(){}
Person(string name,int age):name(name),age(age){}
~Person(){}
void showInfo(){
cout name age endl;
}
bool pSort(Person p){
return this - age p.age;
}
};
void test03()
{
vectorPerson ps;
Person p1(张三,23);
Person p2(李四,29);
Person p3(王五,19);
ps.push_back(p1);
ps.push_back(p2);
ps.push_back(p3);
sort(ps.begin(),ps.end(),mem_fun_ref(Person::pSort));
for_each(ps.begin(),ps.end(),mem_fun_ref(Person::showInfo));
} random_shuffle 作用 : 打乱 语法 /* param beg 容器开始迭代器 param end 容器结束迭代器 */ random_shuffle(iterator beg, iterator end) 示例 void test04()
{
vectorint vs;
vs.push_back(1);
vs.push_back(2);
vs.push_back(3);
vs.push_back(4);
vs.push_back(5);
random_shuffle(vs.begin(), vs.end());
for_each(vs.begin(),vs.end(),[](int x){
cout x ;
});
cout endl;
} reverse 作用 : 翻转 语法 /* param beg 容器开始迭代器 param end 容器结束迭代器 */ reverse(iterator beg, iterator end) 示例 void test05()
{
vectorint vs;
vs.push_back(31);
vs.push_back(2);
vs.push_back(23);
vs.push_back(14);
vs.push_back(5);
sort(vs.begin(),vs.end());
for_each(vs.begin(),vs.end(),[](int x){
cout x ;
});
cout endl;
reverse(vs.begin(),vs.end());
for_each(vs.begin(),vs.end(),[](int x){
cout x ;
});
cout endl;
} 4.拷贝与替换 copy 作用 : 拷贝 语法 /* param beg 容器开始迭代器 param end 容器结束迭代器 param dest 目标起始迭代器 */ copy(iterator beg, iterator end, iterator dest) 示例 void test01()
{
vectorint vs;
vs.push_back(31);
vs.push_back(2);
vs.push_back(23);
vs.push_back(14);
vs.push_back(5);
vectorint newVs;
newVs.resize(vs.size());
copy(vs.begin(),vs.end(),newVs.begin());
for_each(newVs.begin(),newVs.end(),[](int x){
cout x endl;
});
} replace 作用 : 替换 语法 /* param beg 容器开始迭代器 param end 容器结束迭代器 param oldvalue 旧元素 param oldvalue 新元素 */ replace(iterator beg, iterator end, oldvalue, newvalue) 示例 void test02()
{
vectorint vs;
vs.push_back(31);
vs.push_back(2);
vs.push_back(23);
vs.push_back(14);
vs.push_back(5);
replace(vs.begin(),vs.end(),2,20);
for_each(vs.begin(),vs.end(),[](int x){
cout x endl;
});
} replace_if 作用 : 条件替换 语法 /* param beg 容器开始迭代器 param end 容器结束迭代器 param callback 函数回调或者谓词 ( 返回 Bool 类型的函数对象 ) param oldvalue 新元素 */ replace_if(iterator beg, iterator end, _callback, newvalue) 示例 void test03()
{
vectorint vs;
vs.push_back(31);
vs.push_back(2);
vs.push_back(23);
vs.push_back(14);
vs.push_back(5);
replace_if(vs.begin(),vs.end(),[](int x){
return x 20;
},20);
for_each(vs.begin(),vs.end(),[](int x){
cout x endl;
});
} swap 作用 : 交换 语法 /* param c1 容器 1 param c2 容器 2 */ swap(container c1, container c2) 示例 void test04()
{
vectorint v01;
v01.push_back(1);
v01.push_back(2);
v01.push_back(3);
v01.push_back(4);
v01.push_back(5);
vectorint v02;
v02.push_back(6);
v02.push_back(7);
v02.push_back(8);
cout 交换前: endl;
for_each(v01.begin(),v01.end(),[](int x){
cout x ;
});
cout endl;
for_each(v02.begin(),v02.end(),[](int x){
cout x ;
});
cout endl;
swap(v01,v02);
cout 交换后: endl;
for_each(v01.begin(),v01.end(),[](int x){
cout x ;
});
cout endl;
for_each(v02.begin(),v02.end(),[](int x){
cout x ;
});
cout endl;
} 5.常用算数生成算法 accumulate 作用 : 计算容器元素累计总和 语法 /* param beg 容器开始迭代器 param end 容器结束迭代器 param value 累加值 return int 总和 */ accumulate(iterator beg, iterator end, value) 示例 void test01()
{
vectorint v01;
v01.push_back(1);
v01.push_back(2);
v01.push_back(3);
v01.push_back(4);
v01.push_back(5);
int sum 0;
sum accumulate(v01.begin(),v01.end(),0);
cout sum endl;
} fill 作用 : 指定的值赋给指定范围内的所有元素 语法 /* param beg 容器开始迭代器 param end 容器结束迭代器 param value t 填充元素 */ fill(iterator beg, iterator end, value) 示例 void test02()
{
vectorint v01;
v01.push_back(1);
v01.push_back(2);
v01.push_back(3);
v01.push_back(4);
v01.push_back(5);
fill(v01.begin(),v01.end(),10);
for_each(v01.begin(),v01.end(),[](int x){
cout x ;
});
cout endl;
} set_intersection 作用 : 获取交集 语法 /* 注意 : 两个集合必须是有序序列 param beg1 容器 1 开始迭代器 param end1 容器 1 结束迭代器 param beg2 容器 2 开始迭代器 param end2 容器 2 结束迭代器 param dest 目标容器开始迭代器 return 目标容器的最后一个元素的迭代器地址 */ set_intersection(iterator beg1, iterator end1, iterator beg2, iterator end2, iterator dest) 示例 void test03()
{
vectorint v01;
v01.push_back(1);
v01.push_back(2);
v01.push_back(3);
v01.push_back(4);
v01.push_back(5);
vectorint v02;
v02.push_back(1);
v02.push_back(4);
v02.push_back(7);
vectorint v03;
//back_inserter:获取一个插入迭代器
set_intersection(v01.begin(),v01.end(),v02.begin(),v02.end(),back_inse
rter(v03));
for_each(v03.begin(),v03.end(),[](int x){
cout x ;
});
cout endl;
} set_union 作用 : 获取并集 语法 /* 注意 : 两个集合必须是有序序列 param beg1 容器 1 开始迭代器 param end1 容器 1 结束迭代器 param beg2 容器 2 开始迭代器 param end2 容器 2 结束迭代器 param dest 目标容器开始迭代器 return 目标容器的最后一个元素的迭代器地址 */ set_union(iterator beg1, iterator end1, iterator beg2, iterator end2, iterator dest) 示例 void test04()
{
vectorint v01;
v01.push_back(1);
v01.push_back(2);
v01.push_back(3);
v01.push_back(4);
v01.push_back(5);
vectorint v02;
v02.push_back(1);
v02.push_back(4);
v02.push_back(7);
vectorint v03;
//back_inserter:获取一个插入迭代器
set_union(v01.begin(),v01.end(),v02.begin(),v02.end(),back_inserter(v0
3));
for_each(v03.begin(),v03.end(),[](int x){
cout x ;
});
cout endl;
} set_difference 作用 : 取差集 差集 :A 与 B 的差集 , 就是 A 中有 B 中没有的元素集合 , 反之 B 与 A 取差集 , 就是 B 中有 A 中没有的元 素集合 如 A中元素 :1,3,5,7,9 B中元素 :,7,9,11,13 A与 B 的差集就是 :1,3,5 B与 A 的差集就是 :11,13 语法 /* 注意 : 两个集合必须是有序序列 param beg1 容器 1 开始迭代器 param end1 容器 1 结束迭代器 param beg2 容器 2 开始迭代器 param end2 容器 2 结束迭代器 param dest 目标容器开始迭代器 return 目标容器的最后一个元素的迭代器地址 */ set_difference(iterator beg1, iterator end1, iterator beg2, iterator end2, iterator dest) 示例 void test05()
{
vectorint v01;
v01.push_back(1);
v01.push_back(3);
v01.push_back(5);
v01.push_back(7);
v01.push_back(9);
vectorint v02;
v02.push_back(9);
v02.push_back(11);
v02.push_back(13);
vectorint v03;
//back_inserter:获取一个插入迭代器
set_difference(v01.begin(),v01.end(),v02.begin(),v02.end(),back_insert
er(v03));
for_each(v03.begin(),v03.end(),[](int x){cout x ;
});
cout endl;
}