std::basic_string::insert

From cppreference.com
 
 
 
std::basic_string
Member functions
basic_string::basic_string
basic_string::operator=
basic_string::assign
basic_string::get_allocator
Element access
basic_string::at
basic_string::operator[]
basic_string::front (C++11)
basic_string::back (C++11)
basic_string::data
basic_string::c_str
Iterators
basic_string::begin
basic_string::cbegin

(C++11)
basic_string::end
basic_string::cend

(C++11)
basic_string::rbegin
basic_string::crbegin

(C++11)
basic_string::rend
basic_string::crend

(C++11)
Capacity
basic_string::empty
basic_string::size
basic_string::length
basic_string::max_size
basic_string::reserve
basic_string::capacity
basic_string::shrink_to_fit (C++11)
Operations
basic_string::clear
basic_string::insert
basic_string::erase
basic_string::push_back
basic_string::pop_back (C++11)
basic_string::append
basic_string::operator+=
basic_string::compare
basic_string::replace
basic_string::substr
basic_string::copy
basic_string::resize
basic_string::swap
Search
basic_string::find
basic_string::rfind
basic_string::find_first_of
basic_string::find_first_not_of
basic_string::find_last_of
basic_string::find_last_not_of
Constants
basic_string::npos
Non-member functions
operator+
operator==
operator!=
operator<
operator>
operator<=
operator>=
swap(std::basic_string)
operator<<
operator>>
getline
stoi
stol
stoll
(C++11)
(C++11)
(C++11)
stoul
stoull
(C++11)
(C++11)
stof
stod
stold
(C++11)
(C++11)
(C++11)
to_string (C++11)
to_wstring (C++11)
Helper classes
hash<std::string>
hash<std::wstring>
hash<std::u32string>
hash<std::u16string>
(C++11)
 
basic_string& insert( size_type index, size_type count, CharT ch );
(1)
basic_string& insert( size_type index, const CharT* s );
(2)
basic_string& insert( size_type index, const CharT* s, size_type count );
(3)
basic_string& insert( size_type index, const basic_string& str );
(4)
basic_string& insert( size_type index, const basic_string& str,
                      size_type index_str, size_type count );
(5)
iterator insert( iterator pos, CharT ch );
iterator insert( const_iterator pos, CharT ch );
(6) (until C++11)
(since C++11)
void insert( iterator pos, size_type count, CharT ch );
iterator insert( iterator pos, size_type count, CharT ch );
(7) (until C++11)
(since C++11)
template< class InputIt >

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

iterator insert( const_iterator i, InputIt first, InputIt last );
(8) (until C++11)

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

Inserts characters into the string:

1) Inserts count copies of character ch at the position index
2) 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 (effectively calls Traits::length(s).
3) Inserts the first count characters from the character string pointed to by s at the position index. s can contain null characters.
4) Inserts string str at the position index
5) Inserts a string, obtained by str.substr(index_str, count) at the position index
6) Inserts character ch before the character pointed by pos
7) Inserts count copies of character ch before the element pointed to by pos
8) Inserts characters from the range [first, last)
9) Inserts elements from initializer list ilist.

Contents

[edit] Parameters

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

[edit] Return value

1-5) *this
6-9) Iterator following the last inserted character.

[edit] Exceptions

1) std::out_of_range if index > size() and std::length_error if size() + count > max_size().
2) std::out_of_range if index > size() and std::length_error if size() + Traits::length(s) > max_size().
3) std::out_of_range if index > size() and std::length_error if size() + count > max_size().
4) Throws exceptions on the following conditions:
a) std::out_of_range if index > size().
b) std::length_error if size() + str.size() > max_size() where ins_count is the number of characters that will be inserted.
5) Throws exceptions on the following conditions:
a) std::out_of_range if index > size().
b) std::out_of_range if index_str > str.size().
c) std::length_error if size() + ins_count > max_size() where ins_count is the number of characters that will be inserted.
6-9) (none)

[edit] See also

appends characters to the end
(public member function)
appends a character to the end
(public member function)