C ++中的upper_bound
在这里,我们将看到C++STL中的upper_bound()函数。此函数返回一个迭代器,该迭代器指向容器中的第一个元素,该元素被认为位于val之后。语法如下:
iterator upper_bound (const value_type& val); const_iterator upper_bound (const value_type& val) const;
返回值是一个迭代器,指向容器中被认为位于val之后的第一个元素。
示例
#include <iostream>
#include <set>
using namespace std;
int main () {
set<int> myset;
set<int>::iterator itlow,itup;
for (int i = 1; i < 10; i++) myset.insert(i*10);
itup = myset.upper_bound (60);
myset.erase(itup);
cout << "myset包含:";
for (set<int>::iterator it = myset.begin(); it!=myset.end(); ++it)
cout << ' ' << *it;
}输出结果
myset包含: 10 20 30 40 50 60 80 90
热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短