map 的key,默认按照从小到达排序;
upper_bound(4),
#include <iostream> #include <vector> #include <map> #include <algorithm> using namespace std; int main() { map<int, string> mapA; //默认从小到大排序(升序) for(int i=0;i<10;++i) { string str; str ="henry" + std::to_string(10-i); mapA[i]=str; cout <<"key:"<<i<<",val:"<<mapA[i]<<endl; } auto upIt = mapA.upper_bound(4); auto lowIt = mapA.lower_bound(4); cout <<"---------out put upper_bound(4) :"<<endl; for(auto it = mapA.begin(); it!=upIt; ++it) { cout <<"key:"<< it->first<<",val:"<<it->second<<endl;// 0,1,2,3,4 } cout <<endl; cout <<"---------out put lower_bound(4):"<<endl; for(auto it = lowIt; it!=mapA.end(); ++it) { cout <<"key:"<< it->first<<",val:"<<it->second<<endl;//4,5,6,7,8,9 } cout <<endl; cout <<"-----finished -----"<<endl; return 0; }
标签:map,uppper,int,bound,C++,include From: https://www.cnblogs.com/music-liang/p/17121527.html