1、string之substr
string substr (size_t pos = 0, size_t len = npos) const;
产生子串
返回一个新建的初始化为string对象的子串拷贝string对象
从pos开始,跨越len个字符(包括字符串的结尾)。
pos
第一个字符的位置被复制为子串。
如果这是等于字符串的长度,该函数返回一个空字符串。
如果这是大于字符串的长度,它会抛出out_of_range。
len
字符数
2.string之find函数
1、size_t find (const string& str, size_t pos = 0) const; //查找string对象
2、size_t find (const char* s, size_t pos = 0) const; //查找字符串
3、size_t find (const char* s, size_t pos, size_t n) const; //字符串的前n个字符
4、size_t find (char c, size_t pos = 0) const;//查找字符
找到在字符串中第一次出现的位置
str
要寻找的string对象
pos
字符串开始寻找的位置
s
指向字符数组的指针。
n
字符串序列长度
c
要搜索的单个字符
返回值:
找到——返回第一个字符的索引
没有——string::npos
string之rfind
与find正好相反,找到最后出现的字符或字符串。