- C 标准库
- C 标准库
- C++ 标准库
- C++ 库 - 主页
- C++ 库 - <fstream>
- C++ 库 - <iomanip>
- C++ 库 - <ios>
- C++ 库 - <iosfwd>
- C++ 库 - <iostream>
- C++ 库 - <istream>
- C++ 库 - <ostream>
- C++ 库 - <sstream>
- C++ 库 - <streambuf>
- C++ 库 - <原子>
- C++ 库 - <复杂>
- C++ 库 - <异常>
- C++ 库 - <功能>
- C++ 库 - <限制>
- C++ 库 - <语言环境>
- C++ 库 - <内存>
- C++ 库 - <新>
- C++ 库 - <数字>
- C++ 库 - <正则表达式>
- C++ 库 - <stdexcept>
- C++ 库 - <字符串>
- C++ 库 - <线程>
- C++ 库 - <元组>
- C++ 库 - <类型信息>
- C++ 库 - <实用程序>
- C++ 库 - <valarray>
C++ Set 库 - set() 函数
描述
C++ 构造函数std::set::set()构造一个空的集合容器,其中没有元素。
宣言
以下是 std::set::set() 构造函数形式 std::set 标头的声明。
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);
参数
alloc - 将迭代器输入到初始位置。
comp - 用于所有键比较的比较函数对象
返回值
构造函数从不返回任何值。
例外情况
如果抛出任何异常,该成员函数将不起作用。
时间复杂度
常数即 O(1)
例子
以下示例显示了 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
设置.htm