string:insert

C++ Reference

insert

Syntax:

    #include <string>
    iterator insert( iterator i, const char& ch );
    string& insert( size_type index, const string& str );
    string& insert( size_type index, const char* str );
    string& insert( size_type index1, const string& str, size_type index2, size_type num );
    string& insert( size_type index, const char* str, size_type num );
    string& insert( size_type index, size_type num, char ch );
    void insert( iterator i, size_type num, const char& ch );
    void insert( iterator i, input_iterator start, input_iterator end );

The very multi-purpose insert() function either:

  • inserts ch before the character denoted by i,
  • inserts str into the current string, at location index,
  • inserts a substring of str (starting at index2 and num characters long) into the current string, at location index1,
  • inserts num copies of ch into the current string, at location index,
  • inserts num copies of ch into the current string, before the character denoted by i, before the character specified by i.

Related Topics: erase, replace