目录

set::count

描述 (Description)

它在容器中搜索等效于val的元素并返回匹配数。

声明 (Declaration)

以下是std :: set :: count在各种C ++版本中的工作方式。

C++98

size_type count (const value_type& val) const;

C++11

size_type count (const value_type& val) const;

返回值

它返回matche的数量

异常 (Exceptions)

如果抛出异常,则容器中没有更改。

时间复杂

时间复杂度取决于对数。

例子 (Example)

以下示例显示了std :: set :: count的用法。

#include <iostream>
#include <set>
int main () {
   std::set<int> myset;
   for (int i = 1; i < 15;++i) myset.insert(i*5);
   for (int i = 0; i < 5; ++i) {
      std::cout << i;
      if (myset.count(i)!=0)
         std::cout << " is an element of myset.\n";
      else
         std::cout << " is not an element of myset.\n";
   }
   return 0;
}

上述程序将正确编译和执行。

0 is not an element of myset.
1 is not an element of myset.
2 is not an element of myset.
3 is not an element of myset.
4 is not an element of myset.
↑回到顶部↑
WIKI教程 @2018