set
set<string> aset{"a","b","c","d"};
- at 未提供
- [] 未提供
- lower_bound 返回第一个大于或等于的对象
- upper_bound 返回第一个大于的对象
- equal_range 他返回的是一个pair,first为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"};