fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main ()
  7. {
  8. string s;
  9.  
  10. cout << "The string is: " << endl;
  11. cin >> s;
  12.  
  13. string::size_type pos = 0;
  14. do {
  15. pos = s.find('a', pos);
  16. if (pos == string::npos) break;
  17. s.insert(pos, "aa");
  18. // or: s.insert(pos, 2, 'a');
  19. pos += 3;
  20. }
  21. while (true);
  22.  
  23. cout << "The modified string is: " << endl;
  24. cout << s;
  25. }
Success #stdin #stdout 0s 4996KB
stdin
water
stdout
The string is: 
The modified string is: 
waaater