备注
此 API 已过时。替代为 unordered_multimap 类。
返回中元素的数目。键匹配参数指定键的 hash_multimap 的。
size_type count(
const Key& _Key
) const;
参数
- _Key
从 hash_multimap 将与元素的键。
返回值
1,如果 hash_multimap 包含类键匹配参数键的元素;0,如果 hash_multimap 不包含带匹配键的元素。
备注
成员函数返回元素数目在范围中
[lower_bound (_Key ), upper_bound (_Key ) )
哪些具有一个键值 _Key。
在Visual C++ .NET 2003中,成员<hash_map> 和 <hash_set> 头文件不再在std命名空间,而是已经进入了stdext命名空间。 有关更多信息,请参见 stdext 命名空间。
示例
在编译此示例与 /Wp64 标志或在 64 位平台时,编译器将生成警告 C4267。 有关该警告的更多信息,请参见 编译器警告(等级 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;
}
要求
标头: <hash_map>
**命名空间:**stdext