Hi,
I have a written a program using multimap and its not giving me the results I am expecting. I have used pair in my program. There is some problem which I am unable to figure out. Perhaps I am using pair for the first time with multimap.
Here is my code:-
#include <iostream>
#include <map>
#include <set>
using namespace std;
int main ()
{
multimap<string,int> mm;
multimap<string,int>::iterator it;
multimap<string,multimap<string,int> > mymm;
multimap<string,multimap<string,int> >::iterator itx;
pair<multimap<string,pair<string,int> >::iterator,multimap<string,pair<string,int> >::iterator> ii;
mm.insert(pair<string,int>("b",20));
mm.insert(pair<string,int>("b",30));
mm.insert(pair<string,int>("b",40));
mm.insert(pair<string,int>("c",50));
mm.insert(pair<string,int>("c",60));
mm.insert(pair<string,int>("d",60));
mymm.insert(make_pair("1", mm));
mymm.insert(make_pair("1", mm));
mymm.insert(make_pair("2", mm));
mymm.insert(make_pair("2", mm));
mymm.insert(make_pair("3", mm));
mymm.insert(make_pair("3", mm));
for (itx = mymm.begin(); itx != mymm.end(); ++itx)
{
cout << " [" << itx->first << "] " << itx->second.begin()->first << " " << itx->second.begin()->second << endl;
}
return 0;
}
Here are the results:-
[1] b 20
[1] b 20
[2] b 20
[2] b 20
[3] b 20
[3] b 20
Its printing only the first elements
[1] b 20
I expect the results like this:-
[1] b 20
[1] b 30
[2] b 40
[2] b 50
[3] b 60
[3] b 60
I would actually like to filter my results like suppose I want only keys with "2" to be printed:-
[2] b 40
[2] b 50
Thanks