C++ STL 速查

vector 顺序容器
迭代器 begin end rbegin rend cbegin cend crbegin crend
size()
empty()
operator[]
front() 返回元素,不是迭代器
back()
push_back(v) 无返回值
pop_back() 无返回值
insert (pos,[ n,] v),(pos, first, last);返回首个插入的iter.
erase (pos),(first, last);返回删除的下一个iter.
string 顺序容器
迭代器 begin end rbegin rend cbegin cend crbegin crend
operator""s 字面值,不转义,比如‘\0’不停止
size()
empty()
length() 基本不用
operator[]
back() 基本不用
front() 基本不用
append ([n, ]ch),(str[, idx[, n]]),(iter first, iter last),({})
push_back(ch)
pop_back
insert (idx, n, ch),(idx, *[, n]),(idx, str, str_idx[, n]),(pos[, n], ch),(pos, first, last)
erase (idx, n),(pos),(first, last)
replace (idx, n, str[, str_idx[, n]]),(first, last, str)
substr(idx, n=npos) 返回子串
operator += == != < > <= >= <=>
find(str, idx=0) 从idx开始找str,返回首个idx
rfind(str, idx=npos) 反向查找
find_first_of(str, idx=0[, n]) 从idx开始找str中任意一个字符,返回首个idx
find_first_not_of
find_last_of
find_last_not_of
(非成员函数)::
转整数 stoi stol stoll stoul stoull
转浮点数 stof stod stold
to_string(val) 数转字符串
pair doc
make_pair() make_pair(k1, k2);
map 关联容器,哈希map
迭代器 begin end rbegin rend cbegin cend crbegin crend
size()
empty()
operator[key] 有就访问,没有就插入
insert(pair<k, v>) 返回pair<iter, bool>,iter指向pair<k, v>.
erase (iter pos),(iter first, iter last).
find(key) 返回iter(没找到就是尾后迭代器)
count(key)
lower_bound(key) 返回指向首个不小于 key 的元素的迭代器
upper_bound(key) 返回指向首个大于 key 的元素的迭代器
equal_range(key) 返回pair<lower_bound(key), upper_bound(key)>
set 关联容器,集合
迭代器 begin end rbegin rend cbegin cend crbegin crend
size()
empty()
insert(val) 返回pair<iter, bool>,iter指向val
erase
find(key)
count(key)
lower_bound(key)
upper_bound(key)
equal_range(key)
stack 容器适配器,栈
top()
empty()
size()
push(val) 无返回值
pop() 无返回值
queue 容器适配器,队列
front()
back()
empty()
size()
push(val) 无返回值
pop() 无返回值
priority_queue 容器适配器,最大堆
top()
empty()
size()
push(val) 无返回值
pop() 无返回值

C++ STL 速查

func doc
【Non-modifying sequence operations】
for_each Apply function to range (function template)
find Find value in range (function template)
find_if Find element in range (function template)
find_if_not Find element in range (negative condition) (function template)
find_end Find last subsequence in range (function template)
find_first_of Find element from set in range (function template)
count Count appearances of value in range (function template)
count_if Return number of elements in range satisfying condition (function template)
equal Test whether the elements in two ranges are equal (function template)
copy Copy range of elements (function template)
copy_n Copy elements (function template)
copy_if Copy certain elements of range (function template)
copy_backward Copy range of elements backward (function template)
swap Exchange values of two objects (function template)
swap_ranges Exchange values of two ranges (function template)
replace Replace value in range (function template)
replace_if Replace values in range (function template)
replace_copy Copy range replacing value (function template)
replace_copy_if Copy range replacing value (function template)
unique Remove consecutive duplicates in range (function template)
unique_copy Copy range removing duplicates (function template)
reverse Reverse range (function template)
reverse_copy Copy range reversed (function template)
rotate Rotate left the elements in range (function template)
rotate_copy Copy range rotated left (function template)
random_shuffle Randomly rearrange elements in range (function template)
shuffle Randomly rearrange elements in range using generator (function template)
Sorting::
sort Sort elements in range (function template)
stable_sort Sort elements preserving order of equivalents (function template)
partial_sort Partially sort elements in range (function template)
partial_sort_copy Copy and partially sort range (function template)
is_sorted Check whether range is sorted (function template)
is_sorted_until Find first unsorted element in range (function template)
nth_element Sort element in range (function template)
【Binary search (operating on partitioned/sorted ranges)】
lower_bound Return iterator to lower bound (function template)
upper_bound Return iterator to upper bound (function template)
equal_range Get subrange of equal elements (function template)
binary_search Test if value exists in sorted sequence (function template)
【Min/max】
min Return the smallest (function template)
max Return the largest (function template)
minmax Return smallest and largest elements (function template)
min_element Return smallest element in range (function template)
max_element Return largest element in range (function template)
minmax_element Return smallest and largest elements in range (function template)