目录

默认构造函数(Default constructor)

描述 (Description)

C ++构造函数std::set::set()构造一个空集合容器,其中没有元素。

声明 (Declaration)

以下是std :: set :: set()构造函数形式std :: set header的声明。

C++98

explicit set(const key_compare& comp = key_compare(),
             const allocator_type& alloc = allocator_type());

C++11

explicit set(const key_compare& comp = key_compare(),
             const allocator_type& alloc = allocator_type());
explicit set(const allocator_type& alloc);

C++14

set();
explicit set(const key_compare& comp,
             const allocator_type& alloc = allocator_type());
explicit set(const allocator_type& alloc);

参数 (Parameters)

  • alloc - 将迭代器输入到初始位置。

  • comp - 比较函数对象,用于所有键的比较

返回值

构造函数永远不会返回任何值。

异常 (Exceptions)

如果抛出任何异常,此成员函数不起作用。

时间复杂

常数即O(1)

例子 (Example)

以下示例显示了std :: set :: set()构造函数的用法。

#include <iostream>
#include <set>
using namespace std;
int main(void) {
   // Default constructor
   std::set<char> t_set;
   t_set.insert('a');
   t_set.insert('e');
   t_set.insert('i');
   t_set.insert('o');
   t_set.insert('u');
   int size = t_set.size(); 
   std::cout << "Contents of set container t_set = " << size;
   return 0;
}

让我们编译并运行上面的程序,这将产生以下结果 -

Contents of set container t_set = 5
↑回到顶部↑
WIKI教程 @2018