C ++ STL中的multiset lower_bound()与示例
在本教程中,我们将讨论一个程序,以了解C++STL中的多集lower_bound()。
函数lower_bound()返回该元素在容器中的首次存在,该元素等效于所提供的参数,否则它返回的元素立即大于该值。
示例
#include <bits/stdc++.h>
using namespace std;
int main(){
multiset<int> s;
s.insert(1);
s.insert(2);
s.insert(2);
s.insert(1);
s.insert(4);
cout << "The multiset elements are: ";
for (auto it = s.begin(); it != s.end(); it++)
cout << *it << " ";
auto it = s.lower_bound(2);
cout << "\nThe lower bound of key 2 is ";
cout << (*it) << endl;
it = s.lower_bound(3);
cout << "The lower bound of key 3 is ";
cout << (*it) << endl;
it = s.lower_bound(7);
cout << "The lower bound of key 7 is ";
cout << (*it) << endl;
return 0;
}输出结果
The multiset elements are: 1 1 2 2 4 The lower bound of key 2 is 2 The lower bound of key 3 is 4 The lower bound of key 7 is 5
热门推荐
10 感谢学校生日祝福语简短
11 祝贺新婚祝福语古代简短
12 對好友毕业祝福语简短
13 祝福语献给老人的话简短
14 别人复读怎么祝福语简短
15 小红书生日祝福语简短
16 父亲简短结婚祝福语大全
17 新娘对伴娘祝福语简短
18 小考加油文案祝福语简短