fork(2) download
  1. #include <iostream>
  2. #include <boost/algorithm/string.hpp>
  3. using namespace std;
  4. int main()
  5. {
  6. cout << "Enter a string:\n";
  7. string array_1;
  8. getline(cin, array_1);
  9.  
  10. cout << "Enter a string you want to find:\n";
  11. string ch;
  12. getline(cin, ch);
  13.  
  14. cout << "Enter a string you wish to replace " << ch << " with:\n";
  15. string ch2;
  16. cin >> ch2;
  17.  
  18. boost::replace_all(array_1, ch, ch2);
  19.  
  20. cout << "Here is the new string: " << array_1 << '\n';
  21. }
  22.  
Success #stdin #stdout 0.01s 2872KB
stdin
abcllo abcre I am
abc
he
stdout
Enter a string:
Enter a string you want to find:
Enter a string you wish to replace abc with:
Here is the new string: hello here I am