I have 2 classes A and B. I create objects which are then put into a multimap. I want to print the all the keys with their corresponding values. However, my attempt to do this was not so successfull as I could create an iterator. I would like to ask how can I use the equal_range()
method to accomplish this. Thanks in advance!
#include "pch.h"
#include <iostream>
#include <map>
using namespace std;
class A {
int key;
public:
A(int k) {
key = k;
}
A(A ob) {
key = ob.key;
}
int getKey() {
return key;
}
};
class B {
string value;
public:
B(string v) {
value = v;
}
};
multimap <A, B> mp;
int main() {
mp = {
make_pair(A(1),B("Crime and punishment")),
make_pair(A(1),B("The Idiot")),
make_pair(A(1),B("Brothers' Karamazov")),
make_pair(A(2),B("Andreshko")),
make_pair(A(2),B("The Gerak family")),
make_pair(A(3),B("The name of the rose")),
make_pair(A(3),B("Baudolino"))
};
for (auto ml = mp.begin(); ml != mp.end();ml++) {
multimap<pair<int, string>, pair<int, string>>::iterator it;
}
}