set的用法

#include <iostream>
#include <iterator>
#include <set>
#include <string>
using namespace std;
typedef set<string>::const_iterator CIT;
template<class T>
void show(CIT&it,set<T>&s)
{
    for(it=s.begin();it!=s.end();++it)
        cout<<*it<<"\t";
    cout<<endl;
}
int main()
{
    const int N=5;
    string s1[N]={"Mick","Bill","Gate","Rose","Jane"};
    string s2[N]={"张锋","秦平","李力","陆放","胡涛"};
    set<string>name1;
    name1.insert(s1,s1+N);
    set<string>name2(s2,s2+N);
    CIT it;
    cout<<"output every elements of name1"<<endl;
    show(it,name1);
    cout<<"output every elements of name2"<<endl;
    show(it,name2);
    cout<<"find the >or= the key word of “李力”'s first element"<<endl;
    it=name2.lower_bound("李力");
    cout<<*it<<endl;
    cout<<"查找name中大于关键“李力”的第一个元素"<<endl;
    it=name2.upper_bound("李力");
    cout<<*it<<endl;
    system("pause");
    return 0;
 
}
上一篇:查看被删除的但仍由进程占用的文件名


下一篇:阿里新零售速度已实现分钟级配送 将向天猫全品类扩散