0
Maybe it will help ... #include <iostream> #include <string> using namespace std; int main() { string st1("It's my first program"); string st2("your second program"); string st3("third "); cout << "st1: " << st1 << endl; cout << "st2: " << st2 <<endl; cout << "replace 19 characters in st1 with st2:"<<endl; st1.replace(5, 19, st2); cout << st1 << endl; cout<<"replace 6 characters in st2 with st3:"<<endl; st2.replace(5, 6, st3); cout<<st2<<endl; return 0; } Output-> st1: It's my first program st2: your second program replace 19 characters in st1 with st2: It's your second program replace 6 characters in st2 with st3: your third program but for the replacement between st2 and st3 we should add a space after "third" i mean like this "third " ...because ...the word second has 6 characters ...so we put a space to make st3 6 characters.
28th Jan 2020, 9:04 PM
Raziyeh
Raziyeh - avatar