【发布时间】:2020-02-09 19:37:46
【问题描述】:
vector<int> vec = {2,4,3};
vector<int>::iterator it;
it=lower_bound(vec.begin(),vec.end(),3);
cout<<*it;
这会返回 4 而不是 3 的输出
vector<int> vec = {2,3,4};
vector<int>::iterator it;
it=lower_bound(vec.begin(),vec.end(),3);
cout<<*it;
但这会返回正确的输出 3。请帮助我理解为什么它在极端情况下会失败。
【问题讨论】:
-
在第一种情况下,您为什么期望
3?文档说returns an iterator ... to the first element ... that is not less than ...。
标签: c++ algorithm c++11 vector lower-bound