std::basic_string::insert

From Cppreference

Jump to: navigation, search
iterator insert( iterator pos, CharT ch );
iterator insert( const_iterator pos, CharT ch );
(1) (pre-C++11 version)
(C++11 version)

void insert( iterator pos, size_type count, CharT ch );
(2)
basic_string& insert( size_type index, size_type count, CharT ch );
(3)
basic_string& insert( size_type index, const CharT* s );
(4)
basic_string& insert( size_type index, const CharT* s, size_type count );
(5)
basic_string& insert( size_type index, const basic_string& str );
(6)
basic_string& insert( size_type index, const basic_string& str,
                      size_type index_str, size_type count );
(7)
template< class InputIterator >

void insert( iterator i, InputIterator first, InputIterator last );
template< class InputIterator >

iterator insert( const_iterator i, InputIterator first, InputIterator last );
(8) (pre-C++11 version)

(C++11 version)

iterator insert( const_iterator pos, std::initializer_list<CharT> ilist );
(9) (C++11 feature)

Inserts characters into the string:

1) inserts character ch before the character pointed by pos

2) inserts count copies of character ch before the element pointed to by pos

3) inserts count copies of character ch at the position index

4) inserts null-terminated character string pointed to by s at the position index. The length of the string is determined by the first null character.

5) inserts the first count characters from the character string pointed to by s at the position index. s can contain null characters.

6) inserts string str at the position index

7) inserts a string, obtained by str.substr(index_str, count) at the position index

8) inserts characters from the range [first, last)

9) inserts elements from initializer list ilist.

Contents

[edit] Parameters

pos - iterator before which the characters will be inserted
index - position at which the content will be inserted
ch - character to insert
s - pointer to the character string to insert
str - string to insert
first, last - range defining characters to be insert
count - number of characters to insert
index_str - position of the first character in the string str to insert.
ilist - initializer list to insert the characters from

[edit] Return value

1) iterator following the last inserted character.

2-7) *this

8-9) iterator following the last inserted character.

[edit] Complexity

[edit] See also

append
appends characters to the end
(public member function)
push_back
inserts characters to the end
(public member function)