erase function is used to erase elements from the unordered_map. There are three type of erase functions supported by unordered_map :
- erasing by iterator: It takes an iterator as a parameter and erases the key and value present at that iterator.
- erasing by key: It takes a key as a parameter and erases the key and value.
- erase by range: It takes two iterators as a parameter and erases all the key and values present in between (including the starting iterator and excluding the end iterator).
unordered_map.erase(const iteratorStart, const iteratorEnd);
Contents of the unordered_map : 4991==>1 519==>1 40==>0 12==>1 4189==>0 After erasing by Iterator : 519==>1 40==>0 12==>1 4189==>0 After erasing by Key : 519==>1 40==>0 12==>1 After erasing by Range : 519==>1
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- How to erase an element from a vector using erase() and reverse_iterator?
- deque::clear() and deque::erase() in C++ STL
- set::erase in C++ STL
- list erase() function in C++ STL
- multimap::erase() in C++ STL
- map erase() function in C++ STL
- unordered_set erase() function in C++ STL
- unordered_multiset erase() function in C++ STL
- multiset erase() in C++ STL
- unordered_multimap erase in C++ STL
- Different ways to delete elements in std::map (erase() and clear())
- std::string::erase in C++
- Difference between std::remove and vector::erase for vectors
- vector erase() and clear() in C++
- std::sort() in C++ STL
- Kruskal's Minimum Spanning Tree using STL in C++
- Dijkstra’s shortest path algorithm using set in STL
- Dijkstra's Shortest Path Algorithm using priority_queue of STL
- Prim's algorithm using priority_queue in STL
- unordered_map in C++ STL
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.