1 // inserting into a string 2 #include3 #include <string> 4 5 int main () 6 { 7 std::string str="to be question"; 8 std::string str2="the "; 9 std::string str3="or not to be"; 10 std::string::iterator it; 11 12 // used in the same order as described above: 13 str.insert(6,str2); // to be (the )question 14 str.insert(6,str3,3,4); // to be (not )the question 15 str.insert(10,"that is cool",8); // to be not (that is )the question 16 str.insert(10,"to be "); // to be not (to be )that is the question 17 str.insert(15,1,':'); // to be not to be(:) that is the question 18 it = str.insert(str.begin()+5,','); // to be(,) not to be: that is the question 19 str.insert (str.end(),3,'.'); // to be, not to be: that is the question(...) 20 str.insert (it+2,str3.begin(),str3.begin()+3); // (or ) 21 22 std::cout << str << '\n'; 23 return 0; 24 }