#include <iostream>
using namespace std;
void replaceDemo(string s1, string s2, string s3, string s4)
{
cout << "Using positions:"
<< "\n";
s1.replace(0, 7, s2);
cout << s1 << endl;
s4.replace(0, 3, "Hello ");
cout << s4 << endl;
s4.replace(6, 5, s3, 0, 5);
cout << s4 << endl;
s4.replace(6, 5, "to all", 6);
cout << s4 << endl;
s4.replace(12, 1, 3, '!');
cout << s4 << endl;
cout << "\nUsing iterators:"
<< "\n";
s2.replace(s2.begin(), s2.end(), s3);
cout << s2 << "\n";
s1.replace(s1.begin(), s1.begin() + 13, "Example");
cout << s1 << "\n";
s4.replace(s4.end() - 7, s4.end(), "geeks from- here",
12);
cout << s4 << "\n";
s4.replace(s4.end() - 1, s4.end(), s2.begin(),
s2.end());
cout << s4 << "\n";
s4.replace(s4.begin() + 5, s4.begin() + 15, 2, ',');
cout << s4 << "\n";
}
int main()
{
string s1 = "Example of replace";
string s2 = "Demonstration";
string s3 = "GeeksforGeeks";
string s4 = "HeyWorld !";
replaceDemo(s1, s2, s3, s4);
return 0;
}