查找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這是一個非常低的酒吧。太糟糕了,很少有值得評論的地方。 –