查找UPPER_BOUND查找字符串键的UPPER_BOUND在STL地图
我试图找到在STL地图字符串键的UPPER_BOUND,但它没有给我确切的结果。如果你可以运行这个程序,你会发现结果是奇怪的,无论是上面的&下边界指向“qwerzzx”
我的代码中是否有任何错误,或者我错误地解释了上限操作..?
#include<iostream>
#include<cstring>
#include <map>
using namespace std;
int main()
{
map<string, int> testmap;
map<string, int>::iterator poslow;
map<string, int>::iterator posup;
testmap.insert(make_pair<string, int>("asdfghjkliopp", 1));
testmap.insert(make_pair<string, int>("asdfghjklioppswert", 1));
testmap.insert(make_pair<string, int>("sdertppswert", 1));
testmap.insert(make_pair<string, int>("sdertppswedertyuqrt", 1));
testmap.insert(make_pair<string, int>("qwerzzx", 1));
testmap.insert(make_pair<string, int>("qwerzzxasdf", 1));
testmap.insert(make_pair<string, int>("qwsdfgqwerzzx", 1));
testmap.insert(make_pair<string, int>("xcvbqwsdfgqwerzzx", 1));
testmap.insert(make_pair<string, int>("xcvbqwsdersdfgqwerzzx", 1));
poslow = testmap.lower_bound("qw");
posup = testmap.upper_bound("qw");
cout<<"Lower POS ::: "<<poslow->first<<" UPPER POS :: "<<posup->first<<"\n";
testmap.erase(poslow, posup);
}
带有可编译源代码的问题。干得好先生! – john
@john这是一个非常低的酒吧。太糟糕了,很少有值得评论的地方。 –