multiset::count
Gibt die Anzahl der Elemente in einem Multiset zurück, dessen Schlüssel eine Parameter-angegebene Schlüssel entspricht.
size_type count(
const Key& _Key
) const;
Parameter
- _Key
Der Schlüssel der vom Multiset verglichen werden Elemente.
Rückgabewert
Die Anzahl der Elemente im Multiset, dessen Sortierschlüssel die Parametertaste übereinstimmt.
Hinweise
Die Memberfunktion gibt die Anzahl der Elemente im Bereich x zurück
[lower_bound (_Key), upper_bound (_Key)).
Beispiel
Wenn Sie dieses Beispiel mit dem /Wp64 - oder auf einer 64-Bit-Plattform kompiliert, Compilerwarnung wird C4267 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