set::count

返回元素数。键与参数指定的键设置的。

size_type count(
   const Key& _Key
) const;

参数

  • _Key
    从要匹配的元素的键设置。

返回值

1,如果排序关键字参数匹配键集合包含一个元素。 0,如果集合不包含与匹配键的元素。

备注

成员函数返回的元素数。以下范围的:

[lower_bound (_Key),upper_bound (_Key)。

示例

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

// set_count.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main()
{
    using namespace std;
    set<int> s1;
    set<int>::size_type i;

    s1.insert(1);
    s1.insert(1);

    // Keys must be unique in set, so duplicates are ignored
    i = s1.count(1);
    cout << "The number of elements in s1 with a sort key of 1 is: "
         << i << "." << endl;

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

要求

标头: <set>

命名空间: std

请参见

参考

set Class

set::count (STL Samples)

标准模板库