
- C++ Library - Home
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- The C++ STL Library
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- The C++ Advanced Library
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ STL Library Cheat Sheet
- C++ STL - Cheat Sheet
- C++ Programming Resources
- C++ Programming Tutorial
- C++ Useful Resources
- C++ Discussion
C++ multimap::erase() Function
The C++ std::multimap::erase() function is used to remove the elements from a container. This function has 3 primary overloads: one that erases elements by keys, another by iterator, and the third by a range of iterators (you can find the syntaxes of all the variants below).
When used with a key, all the elements with that key are removed. With an iterator the element point to it is erased,and the iterator becomes invalid. For a range, all elements within the specified range are erased.
Syntax
Following is the syntax for std::multimap::erase() function.
iterator erase (const_iterator position); or size_type erase (const key_type& k); or iterator erase (const_iterator first, const_iterator last);
Parameters
- position − It indicates the iterator pointing to a single element to be removed.
- k − It indicates the key to be removed from the multimap.
- first, last − It indicates the iterators specifying a range within the multimap.
Return value
This function returns the number of elements erased for key-based version.
Example
Let's look at the following example, where we are going to erase elements by key.
#include#include
Output
Output of the above code is as follows −
2: CD 3: DE
Example
Consider the following example, where we are going to erase the element by iterator.
#include#include
Output
Following is the output of the above code −
2: B 3: C
Example
In the following example, we are going to erase the element by using the range of the iterator.
#include#include
Output
If we run the above code it will generate the following output −
3: Namaste 3: Vanakam