容器包括vector, deque, list, map, multimap, set, multiset。容器适配器包括基于deque的stack和queue,基于vector的priority_queue。string也实现了stl的接口。
因为编写C++程序时经常需要查找容器的函数接口,故作此总结。C++新引入的容器与函数未引入。主要参考自:STL Containers and Container Adaptors
包括vector,deque,list
ContainerType<T> c;
ContainerType<T> c(num);
ContainerType<T> c(num, val);
ContainerType<T> c(inIterBegin, inIterEnd);
//复制构造函数
ContainerType<T> c(otherLikeContainer);
ContainerType<T> c = otherLikeContainer;
c1 = c2
c1 == c2
c1 != c2
c1 < c2 //按元素逐个比较
c1 <= c2
c1 > c2
c1 >= c2
empty()
size()
max_size()
resize(num, val = default)
begin()
end()
rbegin()
rend()
front()
back()
push_back(val)
insert(iter, val)
insert(iter, num, val)
insert(iter, inIterBegin, inIterEnd)
assign(inIterBegin, inIterEnd)
assign(num, val)
pop_back()
erase(iter)
erase(iterBegin, iterEnd)
clear()
swap(otherLikeContainer)
get_allocator()
reserve(num)
capacity()
merge(otherList) //按照大小顺序合并,二者必须是有序的
merge(otherList, binPred)
remove(val)
remove_if(unPred)
reverse()
sort()
sort(binPred)
splice(iter, otherList) //将otherList中所有元素移动到iter处
splice(iter, otherList, otherIterBegin, otherIterEnd)
unique()
unique(binPred)
at(index) //会检查下标范围
operator[](index)
push_front(val)
pop_front()
包括stack,queue,priority_queue
c1 = c2
empty()
size()
push(val)
pop()
front()
back()
top()
==
!=
<
<=
>
>=
参见The STL Sequential Containers and Container Adaptors,
and their Member Functions
包括map, multimap, set, multiset
c1 = c2
==
!=
<
<=
>
>=
empty() const
size() const
max_size()
begin()
end()
rbegin()
rend()
insert(p, val)
insert(start, end)
erase(someKey)
erase(iter)
erase(start, end)
clear()
count(someKey)
find(someKey) //返回迭代器
lower_bound(someKey) //大于等于someKey的迭代器
upper_bound(someKey) //大于someKey的迭代器
equal_range(someKey)
swap(otherLikeContainer)
get_allocator()
//key和val比较的函数对象
key_comp()
value_comp()
其实不存在特有函数,只是这些函数的接口略有不同
ContainerType<keyType, ValueType> c;
ContainerType<KeyType, ValueType> c(inIterBegin, inIterEnd);
ContainerType<KeyType, ValueType> c(otherLikeContainer);
ContainerType<T> c;
ContainerType<T> c(inIterBegin, inIterEnd);
ContainerType<T> c(otherLikeContainer);
operator[someKey]
//返回值为pair<iterator, true/false(是否已经含有此值)>
insert(val)
//返回iterator
insert(val)
参见The STL Associative Containers and their Member Functions
包括string,bitset等类容器
string s;
string s(c_string_value);
string s(char_array, size_type_count);
string s(string_value);
string s(string_value, size_type_index);
string s(string_value, size_type_index, size_type_count);
string s(size_type_count, char_value);
string s(input_iterator_start, input_iterator_end);
s[i]
s.at(i) //边界检查
s.begin()
s.end()
s.rbegin()
s.rend()
operator+=
s.append(string_value)
s.append(c_string_value)
s.append(size_type_count, char_value)
s.append(c_string_value, size_type_count)
s.append(c_string_value, size_type_index, size_type_count)
s.append(first_input_iterator, last_input_iterator)
//
operator=
s.assign(string_value)
s.assign(c_string_value)
s.assign(size_type_count, char_value)
s.assign(c_string_value, size_type_count)
s.assign(c_string_value, size_type_index, size_type_count)
s.assign(start_input_iterator, end_input_iterator)
s.copy(char_array, size_type_count, size_type_index)
s.c_str() //返回以\0结束的char数组地址,数组归s所有,不要更改
s.data() //返回不以\0结束的char数组地址,数组归s所有,不要更改
s.substr(size_type_index)
s.substr(size_type_index, size_type_count)
s.empty()
s.capacity()
s.length()
s.size()
s.max_size()
s.reserve(size_type_value)
s.resize(size_type_value, char_value)
s.resize(size_type_value)
s.clear()
s.erase() //删除所有字符
s.erase(size_type_index)
s.erase(size_type_index, size_type_count)
s.erase(iterator_position)
s.erase(first_iterator, last_iterator)
//所有的find均返回下标值,若找不到,返回string::npos
//
//查找char
s.find(char_value)
s.find(char_value, size_type_index)
s.rfind(char_value)
s.rfind(char_value, size_type_index)
//
//查找string
s.find(string_value)
s.find(string_value, size_type_index) //从index处开始查找
//从后向前查找
s.rfind(string_value)
s.rfind(string_value, size_type_index)
//查找cstring
s.find(c_string_value, size_type_index, size_type_count)
s.rfind(c_string_value, size_type_index, size_type_count)
//
s.find_first_of(char_value)
s.find_first_of(char_value, size_type_index)
s.find_first_not_of(char_value)
s.find_first_not_of(char_value, size_type_index)
//
//查找在/不在string中的char,返回下标
s.find_first_of(string_value)
s.find_first_of(string_value, size_type_index)
s.find_first_not_of(string_value)
s.find_first_not_of(string_value, size_type_index)
//
s.find_first_of(c_string_value, size_type_index, size_type_count)
s.find_first_not_of(string_value, size_type_index, size_type_count)
//
s.find_last_of(char_value)
s.find_last_of(char_value, size_type_index)
s.find_last_not_of(char_value)
s.find_last_not_of(char_value, size_type_index)
//
s.find_last_of(string_value)
s.find_last_of(string_value, size_type_index)
s.find_last_not_of(string_value)
s.find_last_not_of(string_value, size_type_index)
//
s.find_last_of(c_string_value, size_type_index, size_type_count)
s.find_last_not_of(string_value, size_type_index, size_type_count)
s.insert(size_type_index, string_variable)
s.insert(size_type_index, c_string_value)
s.insert(size_type_index1, string_variable, size_type_index2, size_type_count)
s.insert(size_type_index, c_string_value, size_type_count)
s.insert(size_type_index, size_type_count, char_value)//c++中函数形参总是count在val之前
s.insert(iterator_position, size_type_count, char_value)
s.insert(iterator_position, char_value)
s.insert(iterator_position, input_iterator_first, input_iterator_last)
//
s.push_back(char_value)
s.replace(size_type_index, size_type_count, string_value)
s.replace(iterator_first, iterator_last, string_value
s.replace(size_type_index1, size_type_count1, string_value,
size_type_index2, size_type_count2)
s.replace(size_type_index, size_type_count, c_string_value)
s.replace(iterator_first, iterator_last, c_string_value)
s.replace(size_type_index, size_type_count1,
c_string_value, size_type_count2)
s.replace(iterator_first, iterator_last,
c_string_value, size_type_count)
s.replace(size_type_index, size_type_count1,
size_type_count2, char_value)
s.replace(iterator_first, iterator_last,
size_type_count, char_value)
s.replace(iterator_first, iterator_last,
input_iterator_start, input_iterator_end)
//==, !=, <, > <=, >=已经重载
//
//compare返回值为int:s-other
s.compare(string_value)
s.compare(size_type_index, size_type_count, string_value)
s.compare(size_type_index1, size_type_count1, string_value,
size_type_index2, size_type_count2)
//
s.compare(c_string_value)
s.compare(size_type_index, size_type_count, c_string_value)
s.compare(size_type_index, size_type_count1,
c_string_value, size_type_count2)
s.swap(string_variable)
//
//以下三个非成员函数
swap(string_variable1, string_variable2)
//
getline(inStream, string_variable)
// string结果不包含delimiter
getline(inStream, string_variable, char_delimiter_value)
原文地址:http://blog.csdn.net/caozhk/article/details/44932573