#include <iostream>
using namespace std;
void test01 ()
{
string s1 = "abcdefg";
int pos = s1.find("de");
cout << pos << endl;
pos = s1.rfind("de");
cout << pos << endl;
}
void test02 ()
{
string s1 = "abcdefg";
s1.replace(1, 3, "111");
cout << s1 << endl;
}
int main ()
{
test01();
test02();
return 0;
}
总结:
find查找从左往右,rfind从右往左
find找到字符串后返回查找的第一个字符位置,找不到返回-1
replace在替换时,要指定从哪个位置开始,多少个字符,替换成什么样的字符串