Freigeben über


multiset::count

Gibt die Anzahl der Elemente in einem Multiset zurück, deren Schlüssel eine Parameter-angegebene Schlüssel entspricht.

size_type count( 
   const Key& _Key 
) const;

Parameter

  • _Key
    Der Schlüssel der vom Multiset gefunden werden, Elemente.

Rückgabewert

Die Anzahl der Elemente im Multiset, dessen Sortierschlüssel die Parametertaste übereinstimmt.

Hinweise

Die Memberfunktion wird die Anzahl von Elementen x im Bereich zurück

[lower_bound (_Key), upper_bound (_Key)).

Beispiel

Wenn Sie dieses Beispiel mit dem /Wp64-Flag oder auf einer 64-Bit-Plattform kompiliert, wird C4267 Compilerwarnung generiert. Weitere Informationen über diese Warnung, finden Sie unter Compilerwarnung (Stufe 3) C4267.

// multiset_count.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main()
{
    using namespace std;
    multiset<int> ms1;
    multiset<int>::size_type i;

    ms1.insert(1);
    ms1.insert(1);
    ms1.insert(2);

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

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

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

Anforderungen

Header: <set>

Namespace: std

Siehe auch

Referenz

multiset-Klasse

Standardvorlagenbibliothek