unordered_map erase in C++ STL
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
Want to learn from the best curated videos and practice problems, check out the C++ Foundation Course for Basic to Advanced C++ and C++ STL Course for foundation plus STL. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
My Personal Notes arrow_drop_up