I was wondering how do I retrieve the value of a multi map in C++
Multimap has internal structure represented as std::pair<T_k, T_v>
. It has first, second members. first
is the key and second
is the value associated with the key.
#include <iostream>
#include <map>
using namespace std;
int main(){
multimap<int,int> a;
a.insert(pair<int,int> (1,2));
a.insert(pair<int,int> (1,2));
a.insert(pair<int,int> (1,4));
for (multimap<int,int>::iterator it= a.begin(); it != a.end(); ++it) {
cout << it->first << "\t" << it->second << endl ;
}
return 0;
}
Output :
1 2
1 2
1 4