unordered_multimap clear() function in C++ STL
The unordered_multimap::clear() is a built-in function in C++ STL which clears the contents of the unordered_multimap container. The final size of the container after the call of the function is 0.
Syntax:
unordered_multimap_name.clear()
Parameters: The function does not accept any parameter.
Return Value: It returns nothing.
Below programs illustrates the above function:
Program 1:
// C++ program to illustrate the // unordered_multimap::clear() #include <bits/stdc++.h> using namespace std; int main() { // declaration unordered_multimap<int, int> sample; // inserts key an delement sample.insert({ 10, 100 }); sample.insert({ 10, 100 }); sample.insert({ 20, 200 }); sample.insert({ 30, 300 }); sample.insert({ 15, 150 }); cout << "Key and Elements of multimap are:"; for (auto it = sample.begin(); it != sample.end(); it++) { cout << "\n{" << it->first << ", " << it->second << "}"; } sample.clear(); cout << "\nSize of container after function call: " << sample.size(); return 0; } |
chevron_right
filter_none
Output:
Key and Elements of multimap are:
{15, 150}
{30, 300}
{20, 200}
{10, 100}
{10, 100}
Size of container after function call: 0
Program 2:
// C++ program to illustrate the // unordered_multimap::clear() #include <bits/stdc++.h> using namespace std; int main() { // declaration unordered_multimap<char, char> sample; // inserts element sample.insert({ 'a', 'b' }); sample.insert({ 'a', 'b' }); sample.insert({ 'b', 'c' }); sample.insert({ 'r', 'a' }); sample.insert({ 'c', 'b' }); cout << "Key and Elements of multimap are:"; for (auto it = sample.begin(); it != sample.end(); it++) { cout << "\n{" << it->first << ", " << it->second << "}"; } sample.clear(); cout << "\nSize of container after function call: " << sample.size(); return 0; } |
chevron_right
filter_none
Output:
Key and Elements of multimap are:
{c, b}
{r, a}
{b, c}
{a, b}
{a, b}
Size of container after function call: 0
Recommended Posts:
- multiset clear() function in C++ STL
- multimap clear() function in C++ STL
- ios clear() function in C++ with Examples
- unoredered_set clear() function in C++ STL
- unordered_multiset clear() function in C++ STL
- map::clear() in C++ STL
- set::clear in C++ STL
- unordered_map clear in C++ STL
- std::string::clear in C++
- list::clear() in C++ STL
- vector erase() and clear() in C++
- Different ways to delete elements in std::map (erase() and clear())
- deque::clear() and deque::erase() in C++ STL
- forward_list::clear() and forward_list::erase_after() in C++ STL
- Function Overloading vs Function Overriding in C++
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.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.



