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 类

set::count(STL 示例)

标准模板库