[#bsl-basic_string-0faf-erase-04]
= xref:bsl.adoc[bsl]::xref:bsl/basic_string-0faf.adoc[basic&lowbar;string]::erase
:relfileprefix: ../../
:mrdocs:

`erase` overloads

== Synopses

Declared in `&lt;bslstl&lowbar;string&period;h&gt;`

Erase a character at the specified `position` from this string, and return an iterator providing modifiable access to the character at `position` prior to erasing&period; If no such character exists, return `end()`&period; The behavior is undefined unless `position` is within the half&hyphen;open range `&lsqb;cbegin() &period;&period; cend())&rsqb;`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:bsl/basic_string-0faf/iterator.adoc[iterator]
xref:bsl/basic_string-0faf/erase-0d.adoc[erase](xref:bsl/basic_string-0faf/const_iterator.adoc[const&lowbar;iterator] position);
----

[.small]#xref:bsl/basic_string-0faf/erase-0d.adoc[_» more&period;&period;&period;_]#

Erase from this string a substring defined by the specified pair of `first` and `last` iterators within this string&period; Return an iterator providing modifiable access to the character at the `last` position prior to erasing&period; If no such character exists, return `end()`&period; This method invalidates existing iterators pointing to `first` or a subsequent position&period; The behavior is undefined unless `first` and `last` are both within the range `&lsqb;cbegin() &period;&period; cend()&rsqb;` and &grave;first &lt;&equals; last&grave;&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:bsl/basic_string-0faf/iterator.adoc[iterator]
xref:bsl/basic_string-0faf/erase-0c.adoc[erase](
    xref:bsl/basic_string-0faf/const_iterator.adoc[const&lowbar;iterator] first,
    xref:bsl/basic_string-0faf/const_iterator.adoc[const&lowbar;iterator] last);
----

[.small]#xref:bsl/basic_string-0faf/erase-0c.adoc[_» more&period;&period;&period;_]#

Erase from this string the substring of length the optionally specified `numChars` or `original&period;length() &hyphen; position`, whichever is smaller, starting at the optionally specified `position`&period; If `position` is not specified, the first position is used (i&period;e&period;, `position` is set to 0)&period; Return a reference providing modifiable access to this string&period; If `numChars` equals `npos`, then the remaining length of the string is erased (i&period;e&period;, `numChars` is set to `length() &hyphen; position`)&period; Throw `out&lowbar;of&lowbar;range` if `position &gt; length()`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:bsl/basic_string-0faf.adoc[basic&lowbar;string]&
xref:bsl/basic_string-0faf/erase-09.adoc[erase](
    xref:bsl/basic_string-0faf/size_type.adoc[size&lowbar;type] position = 0,
    xref:bsl/basic_string-0faf/size_type.adoc[size&lowbar;type] numChars = npos);
----

[.small]#xref:bsl/basic_string-0faf/erase-09.adoc[_» more&period;&period;&period;_]#


[.small]#Created with https://www.mrdocs.com[MrDocs]#
