【发布时间】:2016-11-08 10:15:45
【问题描述】:
我有这段简单的代码:
#include <iostream>
#include <set>
using std::set;
int main(int argc, char argv) {
set<int> myset;
set<int>::iterator it_l, it_u;
myset.insert(10);
it_l = myset.lower_bound(11);
it_u = myset.upper_bound(9);
std::cout << *it_l << " " << *it_u << std::endl;
}
这将打印 1 作为 11 的下限,并将 10 作为 9 的上限。
我不明白为什么要打印 1。我希望使用这两种方法来获取给定上限/下限的一系列值。
【问题讨论】:
-
在尝试取消引用迭代器之前检查
myset.end()。
标签: c++ set containers