以std::map为例,
lower_bounder()返回的迭代器指向第一个[大于等于]目标值的元素(以升序为例),
upper_bound()返回的迭代器指向第一个 [大于]目标值的元素(以升序为例)。
直接使用www.cplusplus.com中的例子:
#include <iostream>
#include <map>
int main()
{
std::map<char, int> mymap;
std::map<char, int>::iterator itlow, itup;
mymap['a'] = 20;
mymap['b'] = 40;
mymap['c'] = 60;
mymap['d'] = 80;
mymap['e'] = 100;
itlow = mymap.lower_bound('b'); // itlow points to b
itup = mymap.upper_bound('d'); // itup points to e (not d!)
mymap.erase(itlow, itup); // erases [itlow,itup)
// print content:
for (std::map<char, int>::iterator it = mymap.begin(); it != mymap.end(); ++it)
std::cout << it->first << " => " << it->second << '\n';
return 0;
}