*ps:该小节主要讲string类的字符串检索方法 *
① 常见find系列函数
1) find() : 找出指定子字符串在字符串中第一次出现的索引位置 2) find_first_of() : 找出指定子字符串中的任意字符串在被搜索字符串中第一次出现的索引位置 3)find_last_of() : 找出指定子字符串中的任意字符串在被搜索字符串中最后一次出现的索引位置 3)find_first_not_of(): 找出第一个不用指定子字符串的任意字符匹配的字符 3) rfind() : 找出指定子字符串在字符串中最后一次出现的索引位置
② find()函数
#include#include #include using namespace std; int main() { string river("vivian"); string::size_type first_pos = river.find("vi"); cout<<"string is: "< 运行结果
string is: vivian 0③ find_first_of函数
1)以下是使用过find_first_of查找字符串中出现的数字
#include//#include #include using namespace std; int main() { string str("ab2c3d7R4E6"); string numbers = "123456789"; string letters("abcdRE"); cout<<"检索的字符串:"<


