目录
1,STL初识
1.1 目的
1.2 基本概念
1.3 STL六大组件
1.4 STL中的容器,算法,迭代器
1.5容器算法迭代器初始
1.5.1vector存放内存数据类型
1.5.2 Vector存放自定义数据类型
1.5.3 Vector容器嵌套容器
2,STL常用容器
2.1string容器
2.1.1string基本概念
2.1.2string构造函数
2.1.3string赋值操作
2.1.4string字符串拼接
2.1.5string查找和替换
2.1.6string字符串比较
2.1.7 string字符存取
2.1.8string插入和删除
2.1.9string子串
2.2vector容器
2.2.1 vector基本概念
2.2.2vector构造函数
2.2.3vector赋值操作
2.2.4vector容量和大小
2.2.5vector插入和删除
2.2.6vector数据存取
2.2.7vector互换容器
2.2.8预留空间
2.3deque容器
2.3.1deque容器基本概念
2.3.2deque构造函数
2.3.3deque赋值操作
2.3.4deque大小操作
2.3.5deque插入和删除
2.3.6deque数据存储
2.3.7deque排序
2.4stack容器
2.4.1stack的基本概念
2.4.2stack常用接口
2.5queue容器
2.5.1queue基本概念
2.5.2quene常用接口
2.6 list容器
2.6.1 list基本概念
2.6.2 list构造函数
2.6.3list赋值和交换
2.6.4 list大小操作
2.6.5list插入和删除
2.6.6 list数据存取
2.6.7 list反转与排序
2.7 set/mutiset容器
2.7.1 set基本概念
2.8.2 set构造和赋值
2.8.3set大小和交换
2.8.4 set插入和删除
2.8.5 set查找和统计
2.8.6 set和multise区别
2.8.7pair对组创建
2.8.8 set容器排序
2.9 map/multimap容器
2.9.1 map基本概念
2.9.2 map构造函数
2.9.3 map大小和交换
2.9.4 map插入和删除
2.9.5 map查找和统计
2.9.6 map容器排序
3,STL——函数对象
3.1函数对象
3.1.1函数对象概念
3.1.2函数对象使用
3.2谓词
3.2.1谓词概念
3.2.2一元谓词
3.2.3二元谓词
3.3内建函数对象
3.3.1内建函数对象意义
3.3.2算数仿函数
3.3.3关系仿函数
3.3.4逻辑仿函数
4,STL——常用算法
4.1常用遍历算法
4.1.1 for_each
4.1.2 transform
4.2常用查找算法(所有模板都一样)
4.2.1 find
4.2.2 find_if
4.2.3 adjacent_find
4.2.4 binary_search
4.2.5 count
4.2.6 count_if
4.3常用的排序算法
4.3.1 sort
4.3.2 random_shuffle
4.3.3 merge
4.3.4 reverse
4.4常用拷贝和替换算法
4.4.1 copy
4.4.2 replace
4.4.3 replace_if
4.5常用算术生成算法
4.5.1 accumulate
4.5.2 fill
4.6常用集合算法
4.6.1 set_intersection
4.6.2 set_union
4.6.3 set_different
为了创建一种可重复利用的东西,C++中的面向对象和泛型编程思想,就是复用性的提升
STL是为了建立数据库和算法的一套标准
STL分为六大组件:容器,算法,迭代器,仿函数,适配器(配接器),空间配置器
容器:就是将运用最广泛的一些数据结构实现出来
这些容器分为:序列式容器和关联式容器两种
算法:用有限的步骤解决逻辑上或者数学上的问题
算法分为:质变算法和非质变算法
迭代器:容器和算法之间的粘合剂
提供一种方法,使之能够依序寻找某个容器所含的各个元素,而又无需暴露该容器的内部表示方式
每个容器都有自己的迭代器
种类 | 功能 | 支持运算 |
输入迭代器 | 对数据只读访问 | 只读,支持++,==,-- |
输出迭代器 | 对数据只写访问 | 只写,支持++ |
前向迭代器 | 读写操作,并能向前推进迭代器 | 读写,支持++,==,!= |
双向迭代器 | 读写操作,并能向前和向后操作 | 读写,支持++,-- |
随机访问迭代器 | 读写操作,可以以跳跃式的方式访问任意数据,功能最强的迭代器 | 读写,支持++,--,[n],-n,<,<=,>,>= |
常用的迭代器种类为双向迭代器和随机访问迭代器
STL中最常用的容器为vector,可以理解为数组
容器:vector
算法:for_each
迭代器:vector
#include
using namespace std;
#include
#include
void show(int a)
{
cout << a << endl;
}
void Test()
{
//使用vector容器对象,并且通过模板参数指定容器中存放的数据的类型
vector a;
//向容器中放数据
a.push_back(10);
a.push_back(20);
a.push_back(30);
a.push_back(40);
a.push_back(50);
//每一个容器中都有自己的迭代器
//a.begin()返回迭代器,这个迭代器指向容器中的第一个数据
//a.end()返回迭代器,这个迭代器指向容器中的最后一个元素的下一个位置
//vector::iterator 拿到vector这种容器的迭代类型
vector::iterator P_begin = a.begin();
vector::iterator P_end = a.end();
//第一种遍历方式
while (P_begin != P_end)
{
cout << *P_begin << endl;
P_begin++;
}
//第二种遍历方式
for (vector::iterator i = P_begin; i != P_end; i++)
{
cout << *i;
}
//第三种遍历方式
//使用STL的遍历算法,头文件:algorithm
for_each(P_begin, P_end, show);
}
int main()
{
Test();
system("pause");
return 0;
}
将数据类型变为自定义的,比如类和其他的自己定义出来的东西
#include
using namespace std;
#include
#include
class Person
{
public:
Person(int a, int b)
{
this->a = a;
this->b = b;
}
int a;
int b;
};
void show(int a)
{
cout << a << endl;
}
void Test()
{
Person p1(10, 20);
Person p2(10, 20);
Person p3(10, 20);
Person p4(10, 20);
Person p5(10, 20);
vector a;
//向容器中放数据
a.push_back(p1);
a.push_back(p2);
a.push_back(p3);
a.push_back(p4);
a.push_back(p5);
for (vector::iterator i = a.begin(); i != a.end(); i++)
{
cout << (*i).a << " " << (*i).b << endl;
}
}
void Test1()
{
Person p1(10, 20);
Person p2(10, 20);
Person p3(10, 20);
Person p4(10, 20);
Person p5(10, 20);
vector a;
//向容器中放数据
a.push_back(&p1);
a.push_back(&p2);
a.push_back(&p3);
a.push_back(&p4);
a.push_back(&p5);
for (vector::iterator i = a.begin(); i != a.end(); i++)
{
cout << (*i)->a << " " << (*i)->b << endl;
}
}
int main()
{
Test();
Test1();
system("pause");
return 0;
}
一个数组中嵌套一个小数组,类似于二维数组
#include
using namespace std;
#include
#include
void Test()
{
vector> a;
vector a1;
vector a2;
vector a3;
vector a4;
vector a5;
for (int i = 0; i < 4; i++)
{
//向容器中放数据
a1.push_back(i+1);
a2.push_back(i+2);
a3.push_back(i+3);
a4.push_back(i+4);
a5.push_back(i+5);
}
a.push_back(a1);
a.push_back(a2);
a.push_back(a3);
a.push_back(a4);
a.push_back(a5);
//通过大容器,把所有数据遍历一遍
for (vector>::iterator i = a.begin(); i != a.end(); i++)
{
//(*)it————容器vector
for (vector::iterator j = (*i).begin(); j != (*i).end(); j++)
{
cout << *j <<" ";
}
cout << endl;
}
}
int main()
{
Test();
system("pause");
return 0;
}
注:下面几乎全部都是套用模板,所以有些地方未展示代码,都可以根据模板自己尝试
本质:
string和char*的区别:
特点:
string内部封装了很多成员方法
string s1;
const char *a = "hello world";
string s2(a);
string s3(a);
string s4(5, 'a');
功能:
赋值的函数原型:
string s1=("hello world");
string s2=a;
string s3 = ("h");
s4.assign(a);
s5.append("hello world", 5);
string s6;
s6.assign("hello world");
string s7(5, 'a');
功能:
函数原型:
s1 += "hello";
s1 += ',';
s1 += s2;
s3.append("am");
s3.append("abcdef", 4);
s3.append(s2);
s3.append(s2, 0, 4);
功能描述:
函数原型:
const char *a1 = "wo";
string a2 = "hello world";
int b = a2.find(a1);
int b = a2.find(a1, 2, 1);
const char *a1 = "wo";
string a2 = "hello worldwo";
int b = a2.rfind(a1);
string a2 = "hello world";
a2.replace(1, 3, "aaaaa");
总结:
功能介绍:
比较方式:
函数原型:
#include
using namespace std;
#include
int main()
{
string a = "hello";
string b = "hello";
if (a.compare(b) == 0)
{
cout << "a与b相等" << endl;
}
else if (a.compare(b) == 1)
{
cout << "a大于b" << endl;
}
else
{
cout << "a小于b" << endl;
}
system("pause");
return 0;
}
总结:主要目的是判断是否相等,并不是判断谁大谁小
string中单个字符的存取方式有两种
#include
using namespace std;
#include
int main()
{
string a = "hello";
for (int i = 0; i < a.size(); i++)
{
cout << a[i] << " " << a.at(i) << endl;
}
a[0] = 'a';
cout << a << endl;
a.at(1) = 'a';
cout << a << endl;
system("pause");
return 0;
}
总结:利用“[ ]”和“at()”;
功能描述:
函数原型:
string a = "hello";
a.insert(1, "aaa");
a.erase(1, 3);
功能描述:
函数原型:
string a = "helloasdq";
string b = a.substr(2, 5);
功能:
vector与普通数组区别:
动态扩展:
功能描述:
函数原型:
vector
a;
for (int i = 0; i < 10; i++)
{
a.push_back(i);
}
vector
b(a.begin(), a.end());
vector
c(10, 100);
vector
d(c);
功能描述:
函数原型:
vector
b;
b.assign(a.begin(), a.end());
vector
c;
c = a;
vector
d;
d.assign(10, 100);
功能描述:
函数原型:
if (a.empty())
{
cout << "容器为空" << endl;
}
cout << a.capacity() << endl;
cout << a.size() << endl;
a.resize(5);
a.resize(3, 10);
功能描述:
函数原型:
vector
a;
for (int i = 0; i < 10; i++)
{
a.push_back(i);
}
a.pop_back();
a.insert(a.begin(), 100);
a.insert(a.begin(), 3, 100);
a.erase(a.begin());
a.erase(a.begin(), a.end());
a.clear();
功能描述:
函数原型:
cout << a[1];
cout << a.at(1);
cout << a.front();
cout << a.back();
功能描述:
函数原型:
b.swap(a);
vector(a).swap(a); //当容量过大,但是数据很少时,可以用这种方法收缩内存
(通过匿名对象)
功能描述:
函数原型:
功能:
deque和vector区别:
deque内部工作原理:
中控器用来维护每段缓冲区中的内容,缓冲区中存放真实数据,如果一个缓冲区数据存满之后,则在中控器中开辟新的一块,维护新的一段缓冲器来保存数据。中控器中维护的是每个缓冲区的地址,使得使用deque时,像一片连续的内存空间
deque使用了两个迭代器M_start和M_finish,对首个deque块和末deque块进行控制访问。迭代器iterator共有4个变量域,包括M_first、M_last、M_cur和M_node。M_node存放当前deque块的Map数据项地址,M_first和M_last分别存放该deque块的首尾元素的地址(M_last实际存放的是deque块的末尾字节的地址),M_cur则存放当前访问的deque双端队列的元素地址。
功能描述:
函数原型:
deque
a;
for (int i = 0; i < 5; i++)
{
a.push_back(i);
}
deque
b(a.begin(),a.end());
deque
c(10, 100);
deque
d(c);
功能描述:
函数原型:
deque
d;
d=a;
b.assign(a.begin(), a.end());
c.assign(10, 100);
功能描述:
函数原型:(直接套用模板,没有展示代码部分)
功能描述:
函数原型:(代码实现直接套用模板)
两端插入操作:
指定位置操作:
a.insert(a.begin(),10);
a.insert(a.begin(), 5, 100);
a.erase(a.begin() + 7);
功能描述:
函数原型:(代码实现直接套用模板)
功能描述:
算法:
#include
using namespace std;
#include
#include //标准算法头文件
void show(const deque&a)
{
for (deque::const_iterator i = a.begin(); i != a.end(); i++)
{
cout << *i << " ";
}
cout << endl;
}
int main()
{
deque a;
for (int i = 0; i < 5; i++)
{
a.push_back(i);
}
for (int i = 5; i < 10; i++)
{
a.push_front(i);
}
show(a);
sort(a.begin(),a.end());
show(a);
system("pause");
return 0;
}
注:
概念:stack是一种先进后出的数据结构,它只有一个出口
栈中只有栈顶的元素才可以被外界使用,因此栈中不允许有遍历行为
功能描述:
栈容器常用的对外接口
构造函数:
stack
a;
赋值操作:
数据存取:
大小操作:
stack
a;
for (int i = 0; i < 5; i++)
{
a.push(i);
}
stackb(a);
stackc;
c= a;
while (!a.empty())
{
cout << a.top() << endl;
a.pop();
}
概念:queue是一种先进先出的数据结构,他有两个出口
队列容器允许从队尾新增数据,从队头移除数据,只有队头和队尾才能被外界使用,所以不允许有遍历行为
功能描述:
队列容器常用的对外接口
构造函数:
赋值操作:
数据存取:
cout << a.front() << " " << a.back() << endl;
大小操作:
功能:将数据进行链式存储
链表是一种物理存储单元上非连续的存储结构,数据元素的逻辑顺序是通过链表中的指针链表实现的
链表的组成:链表由一系列结点组成
结点的组成:一个是存储数据单元的数据域,另一个是存储下一个结点地址的指针域
STL中的链表是一个双向循环链表
由于链表的存储方式并不是连续的内存地址,因此链表list中的迭代器只支持前移和后移,属于双向迭代器
list的优点:
list的缺点:
list在插入操作和删除操作都不会造成原有list迭代器失效,这在vector是不成立的
功能描述:
函数原型:
功能描述:
函数原型:
功能描述:
函数原型:(直接套用模板,没有展示代码部分)
功能描述:
函数原型:(代码实现直接套用模板)
两端插入操作:
功能描述:
函数原型:
#include
using namespace std;
#include
#include //标准算法头文件
int main()
{
list a;
for (int i = 0; i < 5; i++)
{
a.push_back(i);
}
list b(a);
while (!a.empty())
{
cout << a.front() << " " << a.back() << endl;
a.pop_back();
}
b.erase(b.begin());
cout << b.front() << endl;
b.remove(3);
system("pause");
return 0;
}
功能描述:
函数原型:
#include
using namespace std;
#include
#include //标准算法头文件
int main()
{
list a;
a.push_front(40);
a.push_front(20);
a.push_front(30);
a.push_front(10);
a.push_front(90);
a.push_front(60);
listb;
b = a;
listc(b);
while (!a.empty())
{
cout << a.front()<<" ";
a.pop_front();
}
cout << endl;
b.reverse();
while (!b.empty())
{
cout << b.front() << " ";
b.pop_front();
}
cout << endl;
c.sort();
while (!c.empty())
{
cout << c.front() << " ";
c.pop_front();
}
system("pause");
return 0;
}
简介:
本质:
set和multise区别:
功能描述:创建set容器以及赋值
构造:
赋值:
功能描述:
函数原型:
功能描述:
函数原型:(代码实现直接套用模板)
for (set
::iterator i = a.begin(); i != a.end();i++)
功能描述:
函数原型:
#include
using namespace std;
#include
#include //标准算法头文件
int main()
{
seta;
a.insert(1);
a.insert(2);
a.insert(3);
a.insert(3); //数字重复,不会插入
a.insert(4);
a.insert(5);
if (a.find(4) != a.end())
{
cout<<"找到数据:" << *a.find(4)<
区别:
功能描述:
两种创建方式:
pair
a(10, 20);
cout << a.first << " " << a.second << endl;
pairb=pair (10, 20);
1.内置数据类型
#include
using namespace std;
#include
#include
class Test
{
public:
bool operator()(int val1, int val2)
{
return val1 > val2;
}
};
int main()
{
seta;
for (int i = 0; i < 5; i++)
{
a.insert(i);
}
for (set::iterator j = a.begin(); j != a.end(); j++)
{
cout << *j << " ";
}
cout << endl;
setb;
for (int i = 0; i < 5; i++)
{
b.insert(i);
}
for (set::iterator j = b.begin(); j != b.end(); j++)
{
cout << *j << " ";
}
system("pause");
return 0;
}
2,自定义数据类型
#include
using namespace std;
#include
#include
#include
class Test
{
public:
Test(string a, int b)
{
this->a = a;
this->b = b;
}
string a;
int b;
};
class Test1
{
public:
bool operator()(const Test &a1, const Test &a2)
{
return a1.b > a2.b;
}
};
int main()
{
Test p1("小明", 10);
Test p2("小红", 20);
Test p3("小华", 30);
set s;
s.insert(p1);
s.insert(p2);
s.insert(p3);
for (set::iterator j = s.begin(); j != s.end(); j++)
{
cout << (*j).a<<" "<<(*j).b<
简介:
本质:
优点:
map和multimap区别:
功能描述:
函数原型:
构造:
赋值:
功能描述:
函数原型:
功能描述:
函数原型:(代码实现直接套用模板)
功能描述:
函数原型:
#include
using namespace std;
#include
利用仿函数进行排序:
class Test
{
public:
bool operator()(int val1, int val2)
{
return val1 > val2;
}
};
概念:
本质:
函数对象(仿函数)是一个类,不是一个函数
特点:
概念:
#include
using namespace std;
#include
#include
class Test
{
public:
bool operator()(int val)
{
return val > 2;
}
};
int main()
{
vectora;
for (int i = 0; i < 5; i++)
{
a.push_back(i);
}
vector::iterator j = find_if(a.begin(), a.end(), Test());
if (j == a.end())
{
cout << "未找到" << endl;
}
else
{
cout << *j << endl;
}
system("pause");
return 0;
}
#include
using namespace std;
#include
#include
class Test
{
public:
bool operator()(int val1,int val2)
{
return val1 > val2;
}
};
int main()
{
vectora;
for (int i = 0; i < 5; i++)
{
a.push_back(i);
}
for (vector::iterator j = a.begin(); j != a.end(); j++)
{
cout << *j << " ";
}
cout << endl;
sort(a.begin(), a.end(), Test());
for (vector::iterator j = a.begin(); j != a.end(); j++)
{
cout << *j << " ";
}
system("pause");
return 0;
}
概念:
分类:
用法:
功能描述:
仿函数原型:
plus
a;
cout << a(10, 20) << endl;
multipliesb;
cout << b(10, 20) << endl;
功能描述:
仿函数原型:
sort(a.begin(), a.end(), greater
());
功能描述:
仿函数原型:
transform(a.begin(), a.end(), b.begin(), logical_not
());
概述:
算法简介:
功能描述:
函数原型:
//beg开始迭代器;end结束迭代器;_func函数或者函数对象
#include
using namespace std;
#include
#include
#include
void show(bool a)
{
cout << a << " ";
}
int main()
{
vectora;
a.push_back(true);
a.push_back(false);
a.push_back(false);
a.push_back(true);
a.push_back(true);
a.push_back(false);
for_each(a.begin(), a.end(), show);
system("pause");
return 0;
}
功能描述:
函数原型:
//beg1源容器开始迭代器;end1源容器结束迭代器;beg2目标容器开始迭代器;_func函数或者函数对象
#include
using namespace std;
#include
#include
#include
bool take(bool a)
{
return a;
}
void show(bool a)
{
cout << a << " ";
}
int main()
{
vectora;
a.push_back(true);
a.push_back(false);
a.push_back(false);
a.push_back(true);
a.push_back(true);
a.push_back(false);
vectorb;
b.resize(a.size());
transform(a.begin(), a.end(), b.begin(),take);
for_each(b.begin(), b.end(), show);
system("pause");
return 0;
}
算法简介:
功能描述:
函数原型:
//beg开始迭代器;end结束迭代器;value查找的元素
#include
using namespace std;
#include
#include
#include
int main()
{
vectora;
for (int i = 0; i < 10; i++)
{
a.push_back(i);
}
vector::iterator b = find(a.begin(), a.end(), 5);
if (b == a.end())
{
cout << "未找到" << endl;
}
else
{
cout << "找到数据" << endl;
}
system("pause");
return 0;
}
功能描述:
函数原型:
//按值查找指定元素,找到返回指定元素的迭代器,找不到的返回结束迭代器end()
//beg开始迭代器;end结束迭代器;_Pred函数或者谓词(返回bool类型的仿函数)
功能描述:
函数原型:
//查找相邻重复元素,返回相邻元素的第一个位置
//beg开始迭代器;end结束迭代器;
功能描述:
函数原型:
//查找相邻指定元素,查到返回true,否则返回false
//在无序中不可用
//beg开始迭代器;end结束迭代器;value查找的元素
功能描述:
函数原型:
//统计元素出现次数
//beg开始迭代器;end结束迭代器;value统计的元素
功能描述:
函数原型:
//按条件统计元素出现次数
//beg开始迭代器;end结束迭代器;_Pred 谓词
算法简介:
功能描述:
函数原型:
按值查找指定元素,找到返回指定元素的迭代器,找不到的返回结束迭代器
//beg开始迭代器;end结束迭代器;_Pred 谓词
功能描述:
函数原型:
//指定范围内的元素随机调整次序
//beg开始迭代器;end结束迭代器;
#include
using namespace std;
#include
#include
#include
#include
void show(int a)
{
cout << a << " ";
}
int main()
{
vectora;
for (int i = 0; i < 10; i++)
{
a.push_back(i);
}
random_shuffle(a.begin(), a.end());
for_each(a.begin(), a.end(), show);
system("pause");
return 0;
}
功能描述:
函数原型:
//两个容器必须有序
//beg1是容器1开始迭代器;end1容器1结束迭代器;beg2容器2开始迭代器;end2容器2结束迭代器;dest目标容器开始迭代器
vectorc;
c.resize(a.size() + b.size());
merge(a.begin(), a.end(),b.begin(),b.end(),c.begin());
for_each(c.begin(), c.end(), show);
功能描述:
函数原型:
//反转指定范围的元素
//beg开始迭代器,end结束迭代器
算法简介:
功能描述:
函数原型:
//按值查找元素,找到返回指定位置的迭代器,找不到返回结束迭代器位置
//beg开始迭代器;end结束迭代器;dest目标起始迭代器
功能描述:
函数原型:
//按值查找元素,找到返回指定位置的迭代器,找不到返回结束迭代器位置
//beg开始迭代器;end结束迭代器;oldvalue 旧元素;newvalue新元素
功能描述:
函数原型:
//按条件替换元素,满足条件则替换
//beg开始迭代器;end结束迭代器;_Pred 谓词;newvalue替换的新元素
4.4.4 swap
功能描述:
函数原型:
//互换两个容器的元素
//c1容器1;c2容器2
注:
算法简介:
#include
using namespace std;
#include
#include
#include
#include
void show(int a)
{
cout << a << " ";
}
int main()
{
vectora;
for (int i = 0; i < 10; i++)
{
a.push_back(i);
}
int b = 0;
b = accumulate(a.begin(), a.end(), 0);
cout << b << endl;
system("pause");
return 0;
}
功能描述:
函数原型:
//beg开始迭代器;end结束迭代器;value起始值
功能描述:
函数原型:
//beg开始迭代器;end结束迭代器;value填充的值
#include
using namespace std;
#include
#include
#include
#include
void show(int a)
{
cout << a << " ";
}
int main()
{
vectora;
for (int i = 0; i < 10; i++)
{
a.push_back(i);
}
fill(a.begin(), a.end(), 0);
for_each(a.begin(), a.end(), show);
system("pause");
return 0;
}
算法简介:
函数原型: set_intersection(iterator beg1;iterator end1;iterator beg2,iterator end2,iterator dest);
//beg1是容器1开始迭代器;end1容器1结束迭代器;beg2容器2开始迭代器;end2容器2结束迭代器;
//dest目标容器开始迭代器
#include
using namespace std;
#include
#include
#include
#include
void show(int a)
{
cout << a << " ";
}
int main()
{
vectora;
for (int i = 0; i < 10; i++)
{
a.push_back(i);
}
vectorb;
for (int i = 5; i < 15; i++)
{
b.push_back(i);
}
vectorc;
c.resize(a.size() + b.size());
set_intersection(a.begin(), a.end(), b.begin(), b.end(), c.begin());
for_each(c.begin(), c.end(), show);
system("pause");
return 0;
}
函数原型:
set_union(iterator beg1;iterator end1;iterator beg2,iterator end2,iterator dest);
//两个集合的并集,两个集合必须是有序序列
//beg1是容器1开始迭代器;end1容器1结束迭代器;beg2容器2开始迭代器;end2容器2结束迭代器;
//dest目标容器开始迭代器
函数原型: set_different(iterator beg1;iterator end1;iterator beg2,iterator end2,iterator dest);
//beg1是容器1开始迭代器;end1容器1结束迭代器;beg2容器2开始迭代器;end2容器2结束迭代器;
//dest目标容器开始迭代器