container-string-查找替换

#include <iostream>

using namespace std;

#include <string>

void test01()

{

string? str1 = "abcdefgde";

int pos = str1.find("d");//find从左往右

if (pos == -1)

{

cout << "没找到" << endl;

}

else

{

cout << "找到" <<pos<< endl;

}

int pos2 = str1.rfind("d"); //rfind从右往左 查到第一个

cout << "找到" << pos2 << endl;

}

void test02()

{

//第二位起,三个字符替换1111是

string? str1 = "abcdefgde";

str1.replace(1, 3, "1111");

cout << "str1= " << str1 << endl;

}

int main()

{

test01();

test02();

system("pause");

return 0;

}

运行:

推荐阅读更多精彩内容