3.1.5 string查找和替换
#include <iostream>
using namespace std;
#include<string>
void test01()
{
string str1 = "abcdefg";
int s=str1.find("df");
cout << s << endl;
s = str1.rfind("g");
cout << s << endl;
}
void test02()
{
string str1 = "abcdefg";
string pos=str1.replace(1, 3, "111111");
cout << pos << endl;
}
int main()
{
test02();
system("pause");
return 0;
}
3.1.4 string拼接
#include <iostream>
using namespace std;
#include <string>
void test01()
{
string str1 = "saa";
str1 += "11";
string str2 = "lol";
str1 += str2;
string str3 = "i ";
str3.append("sss");
str3.append("123445", 4);
str3.append(str2, 1,1 );
cout << str3 << endl;
}
int main()
{
test01();
system("pause");
return 0;
}