描述
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
相關用法
- C++ Set set()用法及代碼示例
- C++ Set cbegin()、cend()用法及代碼示例
- C++ Set upper_bound()用法及代碼示例
- C++ Set max_size()用法及代碼示例
- C++ Set crbegin()、crend()用法及代碼示例
- C++ Set equal_range()用法及代碼示例
- C++ Set emplace_hint()用法及代碼示例
- C++ Set count()用法及代碼示例
- C++ Set insert()用法及代碼示例
- C++ Set get_allocator()用法及代碼示例
- C++ String back()用法及代碼示例
- C++ String append()用法及代碼示例
- C++ Stack push()用法及代碼示例
- C++ String Assign()用法及代碼示例
- C++ Stack empty()用法及代碼示例
- C++ SHRT_MIN用法及代碼示例
- C++ Stack size()用法及代碼示例
- C++ String size()用法及代碼示例
- C++ String resize()用法及代碼示例
- C++ String swap()用法及代碼示例
注:本文由純淨天空篩選整理自 C++ Set Library - set() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。