Udostępnij za pośrednictwem


hash_multimap::count

[!UWAGA]

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

Zwraca liczbę elementów w hash_multimap, w której klucz pasuje do klucza określony parametr.

size_type count( 
   const Key& _Key 
) const;

Parametry

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

Wartość zwracana

1, jeśli hash_multimap zawiera element, w której klucz sortowania pasuje do klucza parametr; 0, jeśli hash_multimap nie zawiera elementu za pomocą uzgadniania klucza.

Uwagi

Element członkowski funkcja zwraca liczbę elementów w zakresie

[lower_bound (_Key ), upper_bound (_Key ) )

które mają wartość klucza _Key.

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_count.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>

int main( )
{
    using namespace std;
    using namespace stdext;
    hash_multimap<int, int> hm1;
    hash_multimap<int, int>::size_type i;
    typedef pair<int, int> Int_Pair;

    hm1.insert(Int_Pair(1, 1));
    hm1.insert(Int_Pair(2, 1));
    hm1.insert(Int_Pair(1, 4));
    hm1.insert(Int_Pair(2, 1));

    // Elements do not need to have unique keys in hash_multimap,
    // so duplicates are allowed and counted
    i = hm1.count(1);
    cout << "The number of elements in hm1 with a sort key of 1 is: "
         << i << "." << endl;

    i = hm1.count(2);
    cout << "The number of elements in hm1 with a sort key of 2 is: "
         << i << "." << endl;

    i = hm1.count(3);
    cout << "The number of elements in hm1 with a sort key of 3 is: "
         << i << "." << endl;
}
  

Wymagania

Nagłówek: <hash_map>

Przestrzeń nazw: stdext

Zobacz też

Informacje

hash_multimap — Klasa

Standardowa biblioteka szablonów