multimap::count

返回中元素的数目。键匹配参数指定键的 multimap 的。

size_type count( 
   const Key& _Key 
) const;

参数

  • _Key
    从 multimap 将与元素的键。

返回值

排序关键字参数匹配键的元素数量;0,如果 multimap 不包含带匹配键的元素。

备注

成员函数返回元素数目在范围中

[lower_bound (_Key),upper_bound (_Key)

具有一个键值 _Key。

示例

在编译此示例与 /Wp64 标志或在 64 位平台时,编译器将生成警告 C4267。 有关该警告的更多信息,请参见 编译器警告(等级 3)C4267

// multimap_count.cpp
// compile with: /EHsc
#include <map>
#include <iostream>

int main( )
{
    using namespace std;
    multimap<int, int> m1;
    multimap<int, int>::size_type i;
    typedef pair<int, int> Int_Pair;

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

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

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

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

要求

标头: <map>

命名空间: std

请参见

参考

multimap 类

标准模板库