Advertisement
193030

String inserting text

Feb 22nd, 2020
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cstdlib>
  4.  
  5. using namespace std;
  6. string ns;
  7.  
  8.  int main()
  9. {
  10.  
  11.    string words = "one two three four five six";
  12.    string word = "zero";
  13.    int found = -1;
  14.    int lastSpace = 0;
  15.    do
  16.    {
  17.        found = words.find(" ", found+1);
  18.        if(found!=-1)
  19.        {
  20.            lastSpace = found;
  21.        }
  22.    }
  23.   // while(found<=words.length()-15);
  24.       while(found!=-1);
  25.  
  26.    //words = words.substr(0,found) + " "+ word +words.substr(found);
  27.    words = words.substr(0,lastSpace) + " "+ word +words.substr(lastSpace);
  28.  
  29.  
  30.    cout << words;
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement