Advertisement
jasonpogi1669

Insert a character in all positions of a given string using C++

Sep 13th, 2021
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.27 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     string s;
  7.     cin >> s;
  8.     char ch = 'x';
  9.     // don't forget the '=' in the for-loop condition
  10.     for (int i = 0; i <= (int) s.size(); i++) {
  11.         cout << s.substr(0, i) + ch + s.substr(i) << '\n';
  12.     }
  13.     return 0;
  14. }
  15.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement