string 函数列表 函数名 描述
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 替代
copy 字符串到空间
find 查找
rfind 反向查找
find_first_of 查找包含子串中的任何字符,返回第一个位置
find_first_not_of 查找不包含子串中的任何字符,返回第一个位置
find_last_of 查找包含子串中的任何字符,返回最后一个位置
find_last_not_of 查找不包含子串中的任何字符,返回最后一个位置
substr 得到字串
compare 比较字符串
operator+ 字符串链接
operator== 判断是否相等
operator!= 判断是否不等于
operator< 判断是否小于
operator>> 从输入流中读入字符串
operator<< 字符串写入输出流
getline 从输入流中读入一行
a) string s;
b) string s(str)
c) string s(str,stridx)
d) string s(str,stridx,strlen)
e) string s(cstr)
f) string s(chars,chars_len)
g) string s(num,c)
h) string s(beg,end)
i) s.~string()
a) =,assign()
b) swap()
c) +=,append(),push_back()
d) insert()
e) erase()
f) clear()
g) replace()
h) +
i) ==,!=,<,<=,>,>=,compare()
j) size(),length()
k) max_size()
l) empty()
m) capacity()
n) reserve()
o) [ ], at()
p) >>,getline()
q) <<
r) copy()
s) c_str()
t) data()
u) substr()
v)查找函数
w)begin() end()
x) rbegin() rend()
y) get_allocator()
string s(“abcd”);
s.compare(“abcd”);
s.compare(“dcba”);
s.compare(“ab”);
s.compare(s);
s.compare(0,2,s,2,2);
s.compare(1,2,”bcx”,2);
s.assign(str);
s.assign(str,1,3);
s.assign(str,2,string::npos);
s.assign(“gaint”);
s.assign(“nico”,5);
s.assign(5,’x’);
s+=str;
s+=”my name is jiayp”;
s+=’a’;
s.append(str);
s.append(str,1,3);
s.append(str,2,string::npos)
s.append(“my name is jiayp”);
s.append(“nico”,5);
s.append(5,’x’);
s.push_back(‘a’);
string s=”il8n”;
s.replace(1,2,”nternationalizatio”);
s.erase(13);
s.erase(7,5);
s.substr();
s.substr(11);
s.substr(5,6);
find()
rfind()
find_first_of()
find_last_of()
find_first_not_of()
find_last_not_of()
整理博客地址:https://www.byvoid.com/zhs/blog/cpp-string
作者是Nicolai M.Josuttis 译者是侯捷/孟岩