Udostępnij za pośrednictwem


hash_multimap::erase

[!UWAGA]

Ten interfejs API jest nieaktualny.Alternatywą jest unordered_multimap — Klasa.

Usuwa element lub szereg elementów w hash_multimap z określonych pozycjach lub usuwa elementy, które odpowiadają określonym kluczem.

iterator erase( 
   iterator _Where 
); 
iterator erase( 
   iterator _First, 
   iterator _Last 
); 
size_type erase( 
   const key_type& _Key 
);

Parametry

  • _Where
    Położenie elementu, który ma zostać usunięty z hash_multimap.

  • _First
    Pozycja pierwszego elementu usunięty z hash_multimap.

  • _Last
    Pozycja tylko poza ostatni element usunięty z hash_multimap.

  • _Key
    Klucz elementów, które mają być usunięte z hash_multimap.

Wartość zwracana

Dla pierwszego funkcji dwóch elementów członkowskich sterująca dwukierunkowy który wyznacza pierwszy element pozostały poza wszelkie elementy usunięte lub wskaźnik na koniec hash_multimap, jeśli nie zawiera żadnego takiego elementu.

Dla trzeciego funkcji członka zwraca liczbę elementów, które zostały usunięte z hash_multimap.

Uwagi

Funkcje składowe nigdy nie wyjątek.

W Visual C++ .NET 2003, elementy członkowskie plików nagłówka <hash_map> i <hash_set> nie są już w przestrzeni nazw std, ale raczej zostały przeniesione do przestrzeni nazw stdext.Zobacz Przestrzeń nazw stdext, aby uzyskać więcej informacji.

Przykład

Podczas kompilowania w tym przykładzie z /Wp64 flagowanie lub na platformie 64-bitowej, zostanie wygenerowany kompilator ostrzeżenie C4267.Aby uzyskać więcej informacji dotyczących tego ostrzeżenia, zobacz Ostrzeżenie kompilatora (poziom 3) C4267.

// hash_multimap_erase.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>

int main()
{
    using namespace std;
    using namespace stdext;
    hash_multimap<int, int> hm1, hm2, hm3;
    hash_multimap<int, int> :: iterator pIter, Iter1, Iter2;
    int i;
    hash_multimap<int, int>::size_type n;
    typedef pair<int, int> Int_Pair;

    for (i = 1; i < 5; i++)
    {
        hm1.insert(Int_Pair (i, i) );
        hm2.insert(Int_Pair (i, i*i) );
        hm3.insert(Int_Pair (i, i-1) );
    }

    // The 1st member function removes an element at a given position
    Iter1 = ++hm1.begin();
    hm1.erase(Iter1);

    cout << "After the 2nd element is deleted, "
         << "the hash_multimap hm1 is:";
    for (pIter = hm1.begin(); pIter != hm1.end(); pIter++)
        cout << " " << pIter -> second;
    cout << "." << endl;

    // The 2nd member function removes elements
    // in the range [_First, _Last)
    Iter1 = ++hm2.begin();
    Iter2 = --hm2.end();
    hm2.erase(Iter1, Iter2);

    cout << "After the middle two elements are deleted, "
         << "the hash_multimap hm2 is:";
    for (pIter = hm2.begin(); pIter != hm2.end(); pIter++)
        cout << " " << pIter -> second;
    cout << "." << endl;

    // The 3rd member function removes elements with a given _Key
    hm3.insert(Int_Pair (2, 5));
    n = hm3.erase(2);

    cout << "After the element with a key of 2 is deleted,\n"
         << " the hash_multimap hm3 is:";
    for (pIter = hm3.begin(); pIter != hm3.end(); pIter++)
        cout << " " << pIter -> second;
    cout << "." << endl;

    // The 3rd member function returns the number of elements removed
    cout << "The number of elements removed from hm3 is: "
         << n << "." << endl;

    // The dereferenced iterator can also be used to specify a key
    Iter1 = ++hm3.begin();
    hm3.erase(Iter1);

    cout << "After another element with a key equal to that of the"
         << endl;
    cout  << " 2nd element is deleted, "
          << "the hash_multimap hm3 is:";
    for (pIter = hm3.begin(); pIter != hm3.end(); pIter++)
        cout << " " << pIter -> second;
    cout << "." << endl;
}
  

Wymagania

Nagłówek: <hash_map>

Przestrzeń nazw: stdext

Zobacz też

Informacje

hash_multimap — Klasa

Standardowa biblioteka szablonów