multimap with list

Hi all,

i'm trying to insert values into this multimap:

1
2
3
4
5
6
7
8
9
multimap<string, list<pair<string, string> > > list_map;
list<pair<string, string> > pair_list;

pair_list.push_back(make_pair("abc", "efg"));
pair_list.push_back(make_pair("abc", "effgg"));
pair_list.push_back(make_pair("aeebc", "eftwg"));
pair_list.push_back(make_pair("abrwwc", "efrewrg"))

list_map.insert(make_pair("key", pair_list));


How can i get all values of the 'list_map' with the key "key"?

I tried this one but i'm just getting the first pair :(

1
2
3
4
for (multimap<string, list<pair<string, string> > >::iterator it = list_map.begin(); it != list_map.end(); ++it)
{
  cout << "  [" << it->first << "] " << it->second.begin()->first << " " <<  it->second.begin()->second << endl;
}


thx to all in advanced




based on your code, list_map consists of only one pair ("key" -> pair_list). Hence, the only value corresponding to "key" is the pair_list. If I right understood, what you need is the range created by two iterators being results of std::equal_range algorithm. Then iterating through this range you'll find all the values with the specific key.
ok .. thx all.

resolved the problem :)
Topic archived. No new replies allowed.