changing parts of string objects : string insert « string « C++ Tutorial






#include <iostream>  
  #include <string>  
  using namespace std;  
    
  int main(){  
     string s1("this is a test");  
     string s2("is");  
     string s3("test");  
    
     s1.erase(0, 7);               
     s1.replace(9, 5, s2);         
     s1.replace(0, 1, "s");        
     s1.insert(0, s3);             
     s1.erase(s1.size()-1, 1);     
     s1.append(3, '!');            
    
     int x = s1.find(' ');         
     while( x < s1.size() ){  
        s1.replace(x, 1, "/");
        x = s1.find(' ');     
     }  
     cout << "s1: " << s1 << endl;  
     return 0;  
  }








15.13.string insert
15.13.1.string.insert()
15.13.2.Insert one string at location 10 of another string
15.13.3.string.insert( 3, string4, 0, string::npos )
15.13.4.changing parts of string objects