Code:
#include iostream
#include map
#include string
using namespace std;
int main ()
{
multimap
multimap
mymm.insert (pair
mymm.insert (pair
mymm.insert (pair
mymm.insert (pair
mymm.insert (pair
mymm.insert (pair
cout<<"Size of the multimap: "<< mymm.size() <
cout << "Multimap contains:\n";
for (it = mymm.begin(); it != mymm.end(); ++it)
cout << (*it).first << " => " << (*it).second << '\n';
for (char c = 'x'; c <= 'z'; c++)
{
cout << "There are " << mymm.count(c) << " elements with key " << c << ":";
multimap
for (it = mymm.equal_range(c).first; it != mymm.equal_range(c).second; ++it)
cout << ' ' << (*it).second;
cout << endl;
}
it = mymm.find('x');
mymm.erase (it);
cout<<"Size of the multimap: "<
// showing contents:
cout << "Multimap contains:\n";
for (it = mymm.begin(); it != mymm.end(); ++it)
cout << (*it).first << " => " << (*it).second << '\n';
return 0;
}
Output:
Size of the multimap: 6
Multimap contains:
x => 100
y => 200
y => 300
y => 400
z => 500
z => 500
There are 1 elements with key x: 100
There are 3 elements with key y: 200 300 400
There are 2 elements with key z: 500 500
Size of the multimap: 5
Multimap contains:
y => 200
y => 300
y => 400
z => 500
z => 500
------------------
(program exited with code: 1)
Press return to continue
More C++ Programs: