【STL set】set multiset

set

 set<string> aset{"a","b","c","d"};
  • at 未提供
  • [] 未提供
  • lower_bound 返回第一个大于或等于的对象
  • upper_bound 返回第一个大于的对象
  • equal_range 他返回的是一个pairfirst为lower_bound 结果second为upper_bound 结果
  • insert
  • emplace 插入
  • emplace_hint 指定位置插入

lower_bound upper_bound equal_range
set 类模板中包含 lower_bound()、upper_bound()、equal_range() 这 3 个成员函数,但它们更适用于 multiset 容器,几乎不会用于操作 set 容器。参考 里面有原话

   set<string> aset{"a","b","b","d"};
   
   auto it = aset.lower_bound("b");
   it -> b
   auto it_b = aset.upper_bound("b");
   if -> d
   auto bi  = aset.equal_range("b");
	bi -> <b,d>

遍历

  set<string>::iterator ittt = aset.begin();
  for (;  ittt != aset.end() ;ittt ++)
  {
      cout << *ittt << endl;
  }

插入

 //set<string> aset{"a","b,""b","d"};//这种不会出错
 set<string> aset{"a","b","d"};
 aset.insert("cttp://c.biancheng.net/stl");
 a b cttp://c.biancheng.net/stl d

emplace 插入

set<string> aset{"a","b","d"};
aset.emplace("f");

emplace_hint 插入指定位置插入,成功返回指向插入元素的迭代器失败返回原来的迭代器 ++aset.begin()

  set<string> aset{"a","b","d"};
  auto aaa =  aset.emplace_hint(++aset.begin(),"Z");
  aaa -> "Z" 
  auto aaa =  aset.emplace_hint(++aset.begin(),"a");
  aaa -> "a" 
  

multiset

可以存储相同元素

  multiset<string> aset{"a","b","b","d"};
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值