#include <algorithm>
#include <vector>
using namespace std;
void main(void)
{
const int size = 10 ;
vector<int> v(size); //说明容器v,其大小为size
vector<int>::iterator start, end, it, pos ; //说明4个泛型指针,即迭代子(迭代器)
int a[size]={54,10,10,303,303,54,54,54,54,10};
//以a数组各元素值初始化容器v
for(int i = 0; i<size; i++)
v[i]=a[i];
start = v.begin() ; //首元素位置
end = v.end() ; //末元素位置
cout<<"v={ " ;
//显示出v中各元素
for(it = start; it != end; it++)
cout << *it << " " ;
cout<<" }"<<endl ;
pos = max_element(start, end) ; //v中第一个最大元素
cout << "The maximum element in v is: " << *pos << endl ;
//从第一个最大元素往后的所有元素
for(it = pos; it != end; it++)
cout << *it << " " ;
cout<<endl ;
pos = min_element(start, end) ; //v中第一个最小元素
cout << "The minimum element in v is: " << *pos << endl ;
//从第一个最小元素往后的所有元素
for(it = pos; it != end; it++)
cout << *it << " " ;
cout<<endl ;
cout<<"count(start, end, 10)= ";
cout<<count(start, end, 10)<<endl; //查找对象10所出现的次数
pos = find(start, end, 303); //查找对象303的首次出现(位置)
cout << "After 'find(start, end, 303)', *pos= " << *pos << endl ;
//从第一个303往后的所有元素
for(it = pos; it != end; it++)
cout << *it << " " ;
cout<<endl ;
pos = unique(start, end) ; //使具有连续相同值的对象只留下一份
cout << "After 'unique', *pos= " << *pos << endl ;
for(it = start; it != pos; it++) //unique操作后的对象序列
cout << *it << " " ;
cout<<endl ;
sort(start, pos); //排序
cout << "After 'sort(start, pos);' "<< endl ;
for(it = start; it != pos; it++) //排序后的结果序列
cout << *it << " " ;
cout<<endl;
cout<<"binary_search(start, end, 54)=>";
cout<<binary_search(start, end, 54); //二分查找对象54是否出现
cout<<endl ;
pos = remove(start, pos, 10); //移去所有的10
cout << "After 'remove(start, pos, 10);' "<<endl ;
for(it = start; it != pos; it++) //移去所有10之后的序列
cout << *it << " " ;
cout<<endl ;
replace(start, pos, 54, 888); //将所有的54替换为888
cout << "After 'replace(start, pos, 54, 888);' "<<endl ;
for(it = start; it != pos; it++) //替换之后的序列
cout << *it << " " ;
cout<<endl ;
}