黑马程序员192
#include
#include
using namespace std;
//查找
void test01()
{
string str1 = “abcdefg”;
int pos = str1.find(“de”);//find与rfind的区别 find从左往右 rfind 从右往左
if (pos == -1)
{
cout << “can’t find!” << endl;
}
else
{
cout << “pos=” << pos << endl;
}
}
//替换
void test02()
{
string str1 = “abcdefg”;
str1.replace(1, 3,“1111”);//从1号位置到3号位置替换成1111
cout << str1;
}
int main()
{
test01();
test02();
}