私はそのような方法で std::map を使用しています:
#include <map>
#include <string>
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
map<string, int> my_map;
my_map.insert(pair<string, int>("Ab", 1));
my_map.insert(pair<string, int>("Abb", 2));
my_map.insert(pair<string, int>("Abc", 3));
my_map.insert(pair<string, int>("Abd", 4));
my_map.insert(pair<string, int>("Ac", 5));
my_map.insert(pair<string, int>("Ad", 5));
cout<<my_map.lower_bound("Ab")->second<<endl;
cout<<my_map.upper_bound("Ab")->second<<endl;
return 0;
}
キーが特定の文字列 ("Ab" など) で始まるすべての値を取得したいと考えています。map::lower_bound を使用して開始イテレータを簡単に取得できます。しかし、どうすれば上限を取得できますか? セット全体を下限から繰り返して、すべてのキーがまだ「Ab」で始まっているかどうかを確認する必要がありますか?