Using the erase Member Function on a Multiset : multiset erase « Set Multiset « C++






Using the erase Member Function on a Multiset

  
#include <set>
#include <iostream>

using namespace std;
typedef multiset <int> MSETINT;

int main ()
{
    MSETINT msetIntegers;

    msetIntegers.insert (43);
    msetIntegers.insert (78);
    msetIntegers.insert (78);
    msetIntegers.insert (-1);
    msetIntegers.insert (124);

    MSETINT::const_iterator iElement;

    cout << msetIntegers.size () << " elements.";

    for ( iElement = msetIntegers.begin (); iElement != msetIntegers.end (); ++ iElement )
        cout << *iElement << endl;

    int nNumberToErase = 2;

    cout << msetIntegers.count (nNumberToErase);
    cout << nNumberToErase << endl;

    msetIntegers.erase (nNumberToErase);

    cout << msetIntegers.size () << " elements.";
    for ( iElement = msetIntegers.begin (); iElement != msetIntegers.end (); ++ iElement )
        cout << *iElement << endl;
    return 0;
}
  
    
  








Related examples in the same category

1.Remove all elements up to element with value 3
2.Remove all elements with value 5
3.Demonstrating multiset erase functions: erase a range
4.Demonstrating multiset erase a found element
5.Demonstrating multiset erase functions