C++

Objectives :

  • File Name : string_insert_split1.cpp
    • Split the destination string at a defined spot, and insert a defined length of a source string in the target string.
      temp = str4.insert(3,str2,9, string::npos);
    • If you don't use string::npos, code will not compile.
    • Also compare with : string_insert1.htm
  • Code: string_insert_split1.txt
 

Step: 1 Create a source file.

Step: 2 Edit and save Source file

Step: 3 Runtime Views:

Step:  Brief Discussion: The selection in the source string starts from left to right.  We are going to compare the point of selection in the source string with following codes

temp = str4.insert(3,str2,9, string::npos);
temp = str4.insert(3,str2,8, string::npos);

Note the change the output, in the following image, "post inserts temp : My ld Six Bullets", where 8 and 9 characters were inserted in the source string after 3rd position.