1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
#include <iostream> #include <string> using namespace std; int main () { string base = "this is a test string."; string str2 = "n example"; string str3 = "sample phrase"; string str4 = "useful.";
string str = base; str.replace(9, 5, str2); str.replace(19, 6, str3, 7, 6); str.replace(8, 10, "just a"); str.replace(8, 6, "a shorty", 7); str.replace(22, 1, 3, '!'); str.replace(str.begin(),str.end()-3,str3); str.replace(str.begin(),str.begin()+6,"replace"); str.replace(str.begin()+8,str.begin()+14,"is coolness",7); str.replace(str.begin()+12,str.end()-4,4,'o'); str.replace(str.begin()+11,str.end(),str4.begin(),str4.end()); std::cout << str << '\n'; return 0; }
|