- #include<iostream>
- #include<cstdlib>
- #include<string>
- #include<algorithm>
- using namespace std;
- int main()
- {
- string str1="honolulu";
- cout<<str1.replace(1,3,"a")<<endl; //halulu
- string str2="honolulu";
- cout<<str2.replace(str2.find("u"),1,"a")<<endl; //honolalu
- string str3="honolulu";
- replace(str3.begin(),str3.end(),'u','a');
- cout<<str3<<endl; //honolala
- system("pause");
- return 0;
- }
複製代碼 |