[#bsl-basic_string-0fb-insert-05]
= xref:bsl.adoc[bsl]::xref:bsl/basic_string-0fb.adoc[basic&lowbar;string&lt;char&gt;]::insert
:relfileprefix: ../../
:mrdocs:

`insert` overloads

== Synopses

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

Insert the specified `character` at the specified `position` in this string, and return an iterator providing modifiable access to the inserted character&period; The behavior is undefined unless `position` is a valid iterator on this string&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:bsl/basic_string-0fb/iterator.adoc[iterator]
xref:bsl/basic_string-0fb/insert-01.adoc[insert](
    xref:bsl/basic_string-0fb/const_iterator.adoc[const&lowbar;iterator] position,
    char character);
----

[.small]#xref:bsl/basic_string-0fb/insert-01.adoc[_» more&period;&period;&period;_]#

Insert at the specified `position` in this string each `CHAR&lowbar;TYPE` object in the specified `values` initializer list, and return an iterator to the first newly&hyphen;inserted character&period; If an exception is thrown (other than by the copy constructor, move constructor, assignment operator, and move assignment operator of `CHAR&lowbar;TYPE`), `&ast;this` is unaffected&period; The behavior is undefined unless `position` is an iterator in the range `&lsqb;begin() &period;&period; end()&rsqb;` (both endpoints included)&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:bsl/basic_string-0fb/iterator.adoc[iterator]
xref:bsl/basic_string-0fb/insert-09.adoc[insert](
    xref:bsl/basic_string-0fb/const_iterator.adoc[const&lowbar;iterator] position,
    std::initializer&lowbar;list&lt;char&gt; values);
----

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

Insert at the specified `position` in this string a copy of the specified `other` string, and return a reference providing modifiable access to this string&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&lt;char&gt;]&
xref:bsl/basic_string-0fb/insert-06.adoc[insert](
    xref:bsl/basic_string-0fb/size_type.adoc[size&lowbar;type] position,
    xref:bsl/basic_string-0faf.adoc[basic&lowbar;string&lt;char&gt;] const& other);
----

[.small]#xref:bsl/basic_string-0fb/insert-06.adoc[_» more&period;&period;&period;_]#

Insert at the specified `position` in this string the specified null&hyphen;terminated `characterString` (of length `CHAR&lowbar;TRAITS&colon;&colon;length(characterString)`), and return a reference providing modifiable access to this string&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&lt;char&gt;]&
xref:bsl/basic_string-0fb/insert-07.adoc[insert](
    xref:bsl/basic_string-0fb/size_type.adoc[size&lowbar;type] position,
    char const* characterString);
----

[.small]#xref:bsl/basic_string-0fb/insert-07.adoc[_» more&period;&period;&period;_]#

Insert at the specified `position` in this string the `bsl&colon;&colon;string&lowbar;view` object, obtained from the specified `other`, and return a reference providing modifiable access to this string&period; Throw `out&lowbar;of&lowbar;range` if `position &gt; length()`&period; Throw `length&lowbar;error` if the length of the resulting string exceeds `max&lowbar;size()`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class STRING&lowbar;VIEW&lowbar;LIKE&lowbar;TYPE&gt;
xref:bsl/basic_string-0faf.adoc[basic&lowbar;string&lt;char&gt;]&
xref:bsl/basic_string-0fb/insert-047.adoc[insert](
    xref:bsl/basic_string-0fb/size_type.adoc[size&lowbar;type] position,
    STRING&lowbar;VIEW&lowbar;LIKE&lowbar;TYPE const& other);
----

[.small]#xref:bsl/basic_string-0fb/insert-047.adoc[_» more&period;&period;&period;_]#

Insert at the specified `position` in this string the specified `numChars` copies of the specified `character`, and return an iterator providing modifiable access to the first inserted character, or a non&hyphen;`const` copy of `position` if `0 &equals;&equals; numChars`&period; The behavior is undefined unless `position` is a valid iterator on this string&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:bsl/basic_string-0fb/iterator.adoc[iterator]
xref:bsl/basic_string-0fb/insert-02.adoc[insert](
    xref:bsl/basic_string-0fb/const_iterator.adoc[const&lowbar;iterator] position,
    xref:bsl/basic_string-0fb/size_type.adoc[size&lowbar;type] numChars,
    char character);
----

[.small]#xref:bsl/basic_string-0fb/insert-02.adoc[_» more&period;&period;&period;_]#

Insert at the specified `position` in this string the specified `numChars` copies of the specified `character`, and return a reference providing modifiable access to this string&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&lt;char&gt;]&
xref:bsl/basic_string-0fb/insert-0f.adoc[insert](
    xref:bsl/basic_string-0fb/size_type.adoc[size&lowbar;type] position,
    xref:bsl/basic_string-0fb/size_type.adoc[size&lowbar;type] numChars,
    char character);
----

[.small]#xref:bsl/basic_string-0fb/insert-0f.adoc[_» more&period;&period;&period;_]#

Insert at the specified `position` in this string the specified initial `numChars` characters in the specified `characterString`, and return a reference providing modifiable access to this string&period; Throw `out&lowbar;of&lowbar;range` if `position &gt; length()`&period; The behavior is undefined unless `characterString` is at least `numChars` long&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:bsl/basic_string-0faf.adoc[basic&lowbar;string&lt;char&gt;]&
xref:bsl/basic_string-0fb/insert-0d.adoc[insert](
    xref:bsl/basic_string-0fb/size_type.adoc[size&lowbar;type] position,
    char const* characterString,
    xref:bsl/basic_string-0fb/size_type.adoc[size&lowbar;type] numChars);
----

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

Insert at the specified `position` in this string the characters in the range starting at the specified `first` iterator and ending right before the specified `last` iterator of the (template parameter) type `INPUT&lowbar;ITER`, and return an iterator providing modifiable access to the first inserted character, or a non&hyphen;`const` copy of `position` if `first &equals;&equals; last`&period; The behavior is undefined unless `position` is a valid iterator on this string, and `first` and `last` refer to a sequence of valid values where `first` is at a position at or before `last`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class INPUT&lowbar;ITER&gt;
xref:bsl/basic_string-0fb/iterator.adoc[iterator]
xref:bsl/basic_string-0fb/insert-040.adoc[insert](
    xref:bsl/basic_string-0fb/const_iterator.adoc[const&lowbar;iterator] position,
    INPUT&lowbar;ITER first,
    INPUT&lowbar;ITER last);
----

[.small]#xref:bsl/basic_string-0fb/insert-040.adoc[_» more&period;&period;&period;_]#

Insert at the specified `position` in this string the optionally specified `numChars` characters starting at the specified `sourcePosition` in the specified `other` string, or the suffix of `other` starting at `sourcePosition` if `sourcePosition &plus; numChars &gt; other&period;length()`&period; If `numChars` is not specified, `npos` is used&period; Return a reference providing modifiable access to this string&period; Throw `out&lowbar;of&lowbar;range` if `position &gt; length()` or `sourcePosition &gt; other&period;length()`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:bsl/basic_string-0faf.adoc[basic&lowbar;string&lt;char&gt;]&
xref:bsl/basic_string-0fb/insert-0b.adoc[insert](
    xref:bsl/basic_string-0fb/size_type.adoc[size&lowbar;type] position,
    xref:bsl/basic_string-0faf.adoc[basic&lowbar;string&lt;char&gt;] const& other,
    xref:bsl/basic_string-0fb/size_type.adoc[size&lowbar;type] sourcePosition,
    xref:bsl/basic_string-0fb/size_type.adoc[size&lowbar;type] numChars = npos);
----

[.small]#xref:bsl/basic_string-0fb/insert-0b.adoc[_» more&period;&period;&period;_]#

Insert at the specified `position` in this string the optionally specified `numChars` characters starting at the specified `sourcePosition` in the `bsl&colon;&colon;string&lowbar;view` object, obtained from the specified `other`, or the suffix of this object starting at `sourcePosition` if `sourcePosition &plus; numChars &gt; other&period;length()`&period; If `numChars` is not specified, `npos` is used&period; Return a reference providing modifiable access to this string&period; Throw `out&lowbar;of&lowbar;range` if `position &gt; length()` or `sourcePosition &gt; other&period;length()`&period; Throw `length&lowbar;error` if the length of the resulting string exceeds `max&lowbar;size()`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class STRING&lowbar;VIEW&lowbar;LIKE&lowbar;TYPE&gt;
xref:bsl/basic_string-0faf.adoc[basic&lowbar;string&lt;char&gt;]&
xref:bsl/basic_string-0fb/insert-04e.adoc[insert](
    xref:bsl/basic_string-0fb/size_type.adoc[size&lowbar;type] position,
    STRING&lowbar;VIEW&lowbar;LIKE&lowbar;TYPE const& other,
    xref:bsl/basic_string-0fb/size_type.adoc[size&lowbar;type] sourcePosition,
    xref:bsl/basic_string-0fb/size_type.adoc[size&lowbar;type] numChars = npos);
----

[.small]#xref:bsl/basic_string-0fb/insert-04e.adoc[_» more&period;&period;&period;_]#


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