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;
 
}
相关文章
|
9月前
|
存储 C++ 容器
C++中set的用法学习
Set是C++ STL(标准模板库)的一个容器类,它用于存储不同的值,并且可以按照特定顺序进行访问和操作。Set是一种基于红黑树实现的关联容器,也就是说它的元素按照固定的顺序排列,且每个元素都唯一。 Set中包含的元素是自动排序的,因此,如果你需要在存储值的同时能够高效的进行查找,那么Set会是一个很好的选择。
189 0
|
10月前
|
调度 C++ 容器
C++中set的用法
⭐一、set的简介 set的中文译为集合,知名见其意,因此set容器也就具有集合的属性啦!而集合这个概念大家应该上数学课应该都是学过的哈,集合它具有确定性、互异性、无序性。当然我们这里重点记住它的互异性就OK了,那么什么是互异性呢?就是说一个集合里边是不会出现两个甚至以上相同的元素的(有我没他,有他没我),说明集合还是比较专一的哈,大家以后对待感情也要专一哦!😉😉😉 还有非常重要的一点就是set容器会自动地对元素进行升序排序(从小到大)
250 0
|
10月前
new Set与...new Set()的区别
new Set与...new Set()的区别,妙用多多
84 0
|
C++ 容器
set以及使用举例--C++基础
set以及使用举例--C++基础
124 0
set以及使用举例--C++基础
|
SQL
update 的一种用法
declare @aa int set @aa = 1update EWC_HT_Contract set ContractCode = a.ContractCode + cast (@aa as nvarchar(10)),@aa = @aa +1 from  (select ContractCode from  ContractWHERE (MasterID = 1) ) as awhere MasterID = 2   SQL Server 2000 里面的通过记录修改另一条记录地方法,还可以修改序号。
666 0
List的Clear方法与RemoveAll方法用法小结
List的Clear方法与RemoveAll方法用法小结http://www.bieryun.com/1055.html 示例代码 [csharp] view plain copy using System; using System.
2318 0