函數列表 函數名 描述
begin 得到指向字符串開頭的Iterator
end 得到指向字符串結尾的Iterator
rbegin 得到指向反向字符串開頭的Iterator
rend 得到指向反向字符串結尾的Iterator
size 得到字符串的大小
length 和size函數功能相同
max_size 字符串可能的最大大小
capacity 在不重新分配內存的情況下,字符串可能的大小
empty 判斷是否爲空
operator[] 取第幾個元素,相當於數組
c_str 取得C風格的const char* 字符串
data 取得字符串內容地址
operator= 賦值操作符
reserve 預留空間
swap 交換函數
insert 插入字符
append 追加字符
push_back 追加字符
operator+= += 操作符
erase 刪除字符串
clear 清空字符容器中所有內容
resize 重新分配空間
assign 和賦值操作符一樣
replace(size_type index, size_type len, string substr) 用子串代替從index開始的len個字符 若len==0相當於插入
replace(size_type index, size_type len, string substr, size_type index2, size_type len2) 用子串的index2開始的len2個字符替代主串中從index開始的len個字符 len==0 相當於插入
copy 字符串到空間
find(string substr,size_type off = 0) 從偏移量off處查找第一個substr出現的位置
rfind 反向查找
find_first_of (string substr, size_type off = 0 ) 從偏移量off處查找包含子串中的任何字符,返回第一個位置
find_first_not_of (string substr, size_type off = 0 ) 從偏移量off處查找不包含子串中的任何字符,返回第一個位置
find_last_of (string substr,size_type off = npos) 到off爲止 查找包含子串中的任何字符,返回最後一個位置
find_last_not_of(string substr,size_type off = npos) 到off爲止 查找不包含子串中的任何字符,返回最後一個位置
substr(size_type index,size_type len) 得到從index開始的len個字串
compare 比較字符串
operator+ 字符串鏈接
operator== 判斷是否相等
operator!= 判斷是否不等於
operator< 判斷是否小於
operator>> 從輸入流中讀入字符串
operator<< 字符串寫入輸出流
getline 從輸入流中讀入一行