CPP   57
strings-insert
Guest on 20th April 2022 02:01:01 AM


  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. #include <string>
  6.  
  7. int main() {
  8.  
  9.     string sentence="Lawrence will go";
  10.     string place=" to the store.";
  11.  
  12.     cout << "The sentence is " << sentence.length() << " characters long." << endl;
  13.     cout << sentence << endl;
  14.  
  15.     cout << "Append: " << place << " " << " to: " << sentence << endl;
  16.     sentence.append(place);
  17.  
  18.  
  19.     cout << "The sentence is " << sentence.length() << " characters long." << endl;
  20.     cout << sentence << endl;
  21.  
  22.     int pos=sentence.find("go");
  23.     sentence.insert(pos,"not ");
  24.     cout << "The sentence is " << sentence.length() << " characters long." << endl;
  25.     cout << sentence << endl;
  26.  
  27. }

Raw Paste

Login or Register to edit or fork this paste. It's free.