string::erase
Remove characters from the string.
Synopsis
string&
erase(
std::size_t index = 0,
std::size_t count = string::npos); (1)
string::iterator
erase(
string::const_iterator pos); (2)
string::iterator
erase(
string::const_iterator first,
string::const_iterator last); (3)
Description
-
(1) removes at most
count
but not more thansize() - pos
characters starting atindex
. -
(2) removes the character at
pos
. -
(3) removes characters in the range
[first, last)
.
All references, pointers, or iterators referring to contained elements are invalidated. Any past-the-end iterators are also invalidated.
Preconditions
pos
, first
, and last
are iterators into this string. first
and last
form a valid range.
Complexity
-
(1) linear in
count
. -
(2) constant.
-
(3) linear in
std::distance(first, last)
.
Exception Safety
Strong guarantee.
Return Value
Parameters
Name | Description |
---|---|
|
The index of the first character to remove. |
|
The number of characters to remove. By default remove until the end of the string. |
|
An iterator referring to the character to erase. |
|
An iterator representing the first character to erase. |
|
An iterator one past the last character to erase. |
Exceptions
Type | Thrown On |
---|---|
|
|