1. Inserting, replacing, and deleting strings in C + +
#include <iostream>#include<algorithm>#include<stdio.h>#include<vector>#include<string>using namespacestd;intMain () {strings ="123456"; //inserts a character before the string is specified.cout << S.insert (2,"ABC") << Endl;//Output: 12ab3456//inserts the first n characters of a specified stringcout << S.insert (2,"ABC",2) << Endl;//12ab3456//replaces a substring of the specified length at the beginning of the specified indexcout << S.replace (2,2,"ABC") << Endl;//12abc56, replace "34" for "ABC"//deletes a specified length of character at the beginning of the specified index stringWord =" the"; size_t Index=S.find (word); if(Index! =string:: NPOs) cout<< s.erase (Index, Word.length ()) << Endl;//1256, deleted " the" return 0;}
C + + (10)-String for INSERT, replace, delete operation