我试过在C++ STL Map中使用lowerbound()。在我使用它,我通过程序像下面测试其功能:C++ map lowerbound()
int main()
{
std::map<int,int> mymap;
std::map<int,int>::iterator itlow;
mymap[1]=20;
mymap[3]=60;
mymap[4]=80;
mymap[5]=100;
itlow=mymap.lower_bound (2);
//Test1
std::cout<<(--itlow)->first<<'\n'; //print 1
std::cout<<itlow->second<<'\n'; //print 20
//Test2
std::cout<<(--itlow)->first<<": "<<itlow->second<<'\n'; //print 1 : 60
}
我单独测试1和2,当我测试1,这意味着,我评论的Test2和相同的反向。 测试1的结果符合我的预期,但我不明白为什么Test2会打印第二个字段而不是20个字段?
测试2有未定义的行为。 – chris 2014-10-19 19:21:22
请问你能具体吗?谢谢! – diane 2014-10-19 19:22:57
[见这里](http://stackoverflow.com/questions/949433/why-are-these-constructs-undefined-behavior)许多这样的例子。还有[this](http://stackoverflow.com/questions/4176328/undefined-behavior-and-sequence-points?rq=1)。 – chris 2014-10-19 19:23:52