string::erase

Remove characters from the string.

Synopsis

Description

  • (1) removes at most count but not more than size() - pos characters starting at index.

  • (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

  • (1) *this.

  • (2) An iterator referring to the character immediately following the removed character, or end() if one does not exist.

  • (3) An iterator referring to the character last previously referred to, or end() if one does not exist.

Parameters

Name Description

index

The index of the first character to remove.

count

The number of characters to remove. By default remove until the end of the string.

pos

An iterator referring to the character to erase.

first

An iterator representing the first character to erase.

last

An iterator one past the last character to erase.

Exceptions

Type Thrown On

boost::system::system_error

pos > size().