Iterators
begin:
end:
rbegin:
rend:
cbegin:
cend:
crbegin:
crend:
Capacity
size:
length:
max_size:
resize:
capacity: 返回实际分配的存储空间的大小,一般大于等于 size 。这样能优化插入等需要重新分配存储空间的操作。
reserve:
clear:
empty:
shrink_to_fit(c++11):
Element access
operator [ ]:
at:
back(c++11):
front(c++11):
Modifiers
assign:
operator +=:
append:
push_back:
insert:
erase:
replace:
swap:
pop_back(c++11):
String operations
c_str:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 // strings and c-strings 2 #include <iostream> 3 #include <cstring> 4 #include <string> 5 6 int main () 7 { 8 std::string str ("Please split this sentence into tokens"); 9 10 char * cstr = new char [str.length()+1]; 11 std::strcpy (cstr, str.c_str()); 12 13 // cstr now contains a c-string copy of str 14 15 char * p = std::strtok (cstr," "); 16 while (p!=0) 17 { 18 std::cout << p << ' '; 19 p = std::strtok(NULL," "); 20 } 21 22 delete[] cstr; 23 return 0; 24 }
data: 返回指向一个字符串的指针。 类似于c_str 中的 字符串首指针。copy: 复制一个子串到一个数组中去,但是这个函数并不会在复制的字符串的最后面加上一个 ‘ ’ 字符。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 // string::copy 2 #include <iostream> 3 #include <string> 4 5 int main () 6 { 7 char buffer[20]; 8 std::string str ("Test string..."); 9 std::size_t length = str.copy(buffer,6,5); 10 buffer[length]='