Demonstrate insert(), erase(), and replace().
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str1("A");
string str2("B");
cout << "Initial strings:\n";
cout << "str1: " << str1 << endl;
cout << "str2: " << str2 << "\n\n";
str1.insert(6, str2);
cout << str1 << "\n\n";
str1.erase(6, 9);
cout << str1 <<"\n\n";
str1.replace(7, 8, str2);
cout << str1 << endl;
return 0;
}
Related examples in the same category