1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
// unordered_multimap::erase
#include <iostream>
#include <unordered_map>
int main ()
{
std::unordered_multimap<std::string,std::string> myumm = {
{"strawberry","red"},
{"banana","yellow"},
{"orange","orange"},
{"lemon","yellow"},
{"apple","red"},
{"apple","green"},
{"pear","green"},
};
// erase examples:
myumm.erase ( myumm.begin() ); // erasing by iterator
myumm.erase ("apple"); // erasing by key (erases 2 elements)
myumm.erase ( myumm.find("orange"), myumm.end() ); // erasing by range
// show content:
for ( auto& x: myumm )
std::cout << x.first << ": " << x.second << std::endl;
return 0;
}
| |