A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/cpp/unordered_multiset-clear-function-in-c-stl/ below:

unordered_multiset clear() function in C++ STL

unordered_multiset clear() function in C++ STL

Last Updated : 02 Aug, 2018

The

unordered_multiset::clear()

is a built-in function in C++ STL which clears the contents of the unordered_multiset container. The final size of the container after the call of the function is 0.

Syntax:
unordered_multiset_name.clear()
Parameters:

The function does not accept any parameter.

Return Value:

It returns nothing. Below programs illustrates the above function:

Program 1: CPP
// C++ program to illustrate the
// unordered_multiset::clear() function
#include <bits/stdc++.h>
using namespace std;

int main()
{

    // declaration
    unordered_multiset<int> sample;

    // inserts element
    sample.insert(11);
    sample.insert(11);
    sample.insert(11);
    sample.insert(12);
    sample.insert(13);
    sample.insert(13);
    sample.insert(14);

    cout << "Elements: ";

    for (auto it = sample.begin(); it != sample.end(); it++) {
        cout << *it << " ";
    }

    sample.clear();

    cout << "\nSize of container after function call: " 
         << sample.size();

    return 0;
}
Output:
Elements: 14 11 11 11 12 13 13 
Size of container after function call: 0
Program 2: CPP
// C++ program to illustrate the
// unordered_multiset::clear() function
#include <bits/stdc++.h>
using namespace std;

int main()
{

    // declaration
    unordered_multiset<int> sample;

    // inserts element
    sample.insert(1);
    sample.insert(1);
    sample.insert(1);
    sample.insert(2);
    sample.insert(3);
    sample.insert(4);
    sample.insert(3);

    cout << "Elements: ";

    for (auto it = sample.begin(); it != sample.end(); it++) {
        cout << *it << " ";
    }

    sample.clear();

    cout << "\nSize of container after function call: " 
         << sample.size();

    return 0;
}
Output:
Elements: 1 1 1 2 3 3 4 
Size of container after function call: 0


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4