string::replace
Replace a substring with another string.
Synopsis
string&
replace(
std::size_t pos,
std::size_t count,
string_view sv); (1)
string&
replace(
string::const_iterator first,
string::const_iterator last,
string_view sv); (2)
template<
class InputIt>
string&
replace(
string::const_iterator first,
string::const_iterator last,
InputIt first2,
InputIt last2); (3)
string&
replace(
std::size_t pos,
std::size_t count,
std::size_t count2,
char ch); (4)
string&
replace(
string::const_iterator first,
string::const_iterator last,
std::size_t count2,
char ch); (5)
Description
-
(1) replaces
std::min(count, size() - pos)
characters starting at indexpos
with those ofsv
. -
(2) replaces the characters in the range
[first, last)
with those ofsv
. -
(3) replaces the characters in the range
[first, last)
with those of[first2, last2)
. -
(4) replaces
std::min(count, size() - pos)
characters starting at indexpos
withcount2
copies ofch
. -
(5) replaces the characters in the range
[first, last)
withcount2
copies ofch
.
All references, pointers, or iterators referring to contained elements are invalidated. Any past-the-end iterators are also invalidated.
Preconditions
[first, last)
is a valid range. [first2, last2)
is a valid range.
Constraints
InputIt
satisfies LegacyInputIterator.
Exception Safety
Strong guarantee.
Template Parameters
Type | Description |
---|---|
|
The type of the iterators. |
Return Value
*this
Parameters
Name | Description |
---|---|
|
The index to replace at. |
|
The number of characters to replace. |
|
The |
|
An iterator referring to the first character to replace. |
|
An iterator one past the end of the last character to replace. |
|
An iterator referring to the first character to replace with. |
|
An iterator one past the end of the last character to replace with. |
|
The number of characters to replace with. |
|
The character to replace with. |
Exceptions
Type | Thrown On |
---|---|
|
The resulting string’s size would have exceeded |