C++;映射lowerbound() 我尝试在C++ STL映射中使用LealError()。在使用之前,我通过如下程序测试其功能: 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 } int main() { std::map mymap; std::map::迭代器itlow; mymap[1]=20; mymap[3]=60; mymap[4]=80; mymap[5]=100; itlow=mymap.lower_界(2); //测试1 std::cout

C++;映射lowerbound() 我尝试在C++ STL映射中使用LealError()。在使用之前,我通过如下程序测试其功能: 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 } int main() { std::map mymap; std::map::迭代器itlow; mymap[1]=20; mymap[3]=60; mymap[4]=80; mymap[5]=100; itlow=mymap.lower_界(2); //测试1 std::cout,c++,map,iterator,C++,Map,Iterator,未指定(-itlow)->first是在itlow->second之前还是之后求值。如果之前求值,则得到20;否则得到60 请参阅。测试2有未定义的行为。请您更具体一点好吗?谢谢!有很多这样的示例。还有。代码未生成print 1:60可能是一条注释。此外,测试1使用第一个map元素,测试2未引用无效迭代器。您得到了1:60,但您可以得到其他值…您无法读取和write toitlow“序列点之间”。@chris:那么你是说它是未定义的而不是未指定的?好吧,我想如果可以相信的话,它是在C++11之前

未指定
(-itlow)->first
是在
itlow->second
之前还是之后求值。如果之前求值,则得到
20
;否则得到
60


请参阅。

测试2有未定义的行为。请您更具体一点好吗?谢谢!有很多这样的示例。还有。代码未生成
print 1:60
可能是一条注释。此外,测试1使用第一个map元素,测试2未引用无效迭代器。您得到了1:60,但您可以得到其他值…您无法读取和write to
itlow
“序列点之间”。@chris:那么你是说它是未定义的而不是未指定的?好吧,我想如果可以相信的话,它是在C++11之前,而不是之后。事情如何微妙地改变总是很有趣的。