find 与 rfind
# include <bits/stdc++.h>
using namespace std;
int main ()
{
string a = "abcdefde",b = "de";
int pos1 = a.find(b);
cout<<pos1<<endl;
int pos2 = a.rfind(b);
cout<<pos2<<endl;
return 0;
}
replace
string a.replace(int pos,int n,const char *str);
# include <bits/stdc++.h>
using namespace std;
int main ()
{
string a = "hello world",b = "C++";
a.replace(6,5,b);
cout<<a<<endl;
}
insert 与 erase
insert(int pos,const char *str);
erase(int pos,int n)
# include <bits/stdc++.h>
using namespace std;
int main ()
{
string a = "hello ",b = "lll";
a.insert(1,b);
cout<<a<<endl;
a.erase(1,3);
cout<<a<<endl;
}
substr
substr(int pos,int n);
# include <bits/stdc++.h>
using namespace std;
int main ()
{
string QQemail = "414750422@qq.com";
int pos = QQemail.find("@");
string SubStr = QQemail.substr(0,pos);
cout<<SubStr<<endl;
return 0;
}