string::insert
Insert characters at the specified index.
Synopsis
string&
insert(
std::size_t pos,
string_view sv); (1)
string&
insert(
std::size_t pos,
std::size_t count,
char ch); (2)
string&
insert(
string::size_type pos,
char ch); (3)
template<
class InputIt>
string&
insert(
string::size_type pos,
InputIt first,
InputIt last); (4)
Description
-
(1) inserts
sv. -
(2) inserts
countcopies ofch. -
(3) inserts the character
ch. -
(4) inserts characters from the range
[first, last).
The first character is inserted at the index pos. All references, pointers, or iterators referring to contained elements are invalidated. Any past-the-end iterators are also invalidated.
Constraints
InputIt satisfies LegacyInputIterator.
Preconditions
[first, last) is a valid range.
Exception Safety
-
(1)–(3) strong guarantee.
-
(4) strong guarantee if
InputItsatisfies LegacyForwardIterator, basic guarantee otherwise.
Template Parameters
| Type | Description |
|---|---|
|
The type of the iterators. |
Return Value
*this
Parameters
| Name | Description |
|---|---|
|
The index to insert at. |
|
The |
|
The number of characters to insert. |
|
The character to insert. |
|
The beginning of the character range. |
|
The end of the character range. |
Exceptions
| Type | Thrown On |
|---|---|
|
The size of the string would exceed |
|
|