multimap::count

返回元素数。键匹配一个参数指定键的基于的。

size_type count(
   const Key& _Key
) const;

参数

  • _Key
    从基于将匹配的元素的键。

返回值

排序关键字参数匹配键的元素数,0,如果基于不包含具有匹配键的元素。

备注

成员函数返回的元素数。该范围的

[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 Class

标准模板库