multiset::count

返回元素数。键匹配一个参数指定键的多个集的。

size_type count(
   const Key& _Key
) const;

参数

  • _Key
    从多个集将匹配的元素的键。

返回值

排序关键字参数匹配键的元素数目。多个集的。

备注

成员函数返回的元素数 x 在范围

[lower_bound (_Key),upper_bound (_Key)。

示例

当编译此示例与 /Wp64 标记或在64位平台时,警告的编译器C4267将生成。有关此警告的更多信息,请参见 编译器警告(等级 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;
}
  
  
  

要求

标头: <set>

命名空间: std

请参见

参考

multiset Class

标准模板库