container-string-查找替换

2019-08-29  本文已影响0人  人不知QAQ

#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;

}

运行:

上一篇 下一篇

猜你喜欢

热点阅读