[string.erase]

# 27 Strings library [[strings]](./#strings)

## 27.4 String classes [[string.classes]](string.classes#string.erase)

### 27.4.3 Class template basic_string [[basic.string]](basic.string#string.erase)

#### 27.4.3.7 Modifiers [[string.modifiers]](string.modifiers#string.erase)

#### 27.4.3.7.5 basic_string​::​erase [string.erase]

[ð](#lib:erase,basic_string)

`constexpr basic_string& erase(size_type pos = 0, size_type n = npos);
`

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3864)

*Effects*: Determines the effective length xlen of the string to be removed as the smaller of n andsize() - pos[.](#1.sentence-1)

Removes the characters in the range [begin() + pos, begin() + pos + xlen)[.](#1.sentence-2)

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3871)

*Returns*: *this[.](#2.sentence-1)

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3875)

*Throws*: out_of_range if pos> size()[.](#3.sentence-1)

[ð](#lib:erase,basic_string_)

`constexpr iterator erase(const_iterator p);
`

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3888)

*Preconditions*: p is a valid dereferenceable iterator on *this[.](#4.sentence-1)

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3892)

*Effects*: Removes the character referred to by p[.](#5.sentence-1)

[6](#6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3896)

*Returns*: An iterator which points to the element immediately following p prior to
the element being erased[.](#6.sentence-1)

If no such element exists,end() is returned[.](#6.sentence-2)

[7](#7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3904)

*Throws*: Nothing[.](#7.sentence-1)

[ð](#lib:erase,basic_string__)

`constexpr iterator erase(const_iterator first, const_iterator last);
`

[8](#8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3915)

*Preconditions*: first and last are valid iterators on*this[.](#8.sentence-1)

[first, last) is a valid range[.](#8.sentence-2)

[9](#9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3920)

*Effects*: Removes the characters in the range
[first, last)[.](#9.sentence-1)

[10](#10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3925)

*Returns*: An iterator which points to the element pointed to by last prior to
the other elements being erased[.](#10.sentence-1)

If no such element exists,end() is returned[.](#10.sentence-2)

[11](#11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3933)

*Throws*: Nothing[.](#11.sentence-1)

[ð](#lib:pop_back,basic_string)

`constexpr void pop_back();
`

[12](#12)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3944)

*Hardened preconditions*: empty() is false[.](#12.sentence-1)

[13](#13)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3948)

*Effects*: Equivalent to erase(end() - 1)[.](#13.sentence-1)

[14](#14)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3952)

*Throws*: Nothing[.](#14.sentence-1)
