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

Constructors

== Synopses

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

Create an empty string using a default&hyphen;constructed allocator&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:bsl/basic_string-0faf/2constructor-0d7.adoc[basic&lowbar;string]() noexcept;
----

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

Create a string that has the same value as the specified `original` string&period; Use the allocator returned by &apos;bsl&colon;&colon;allocator&lowbar;traits&lt;ALLOCATOR&gt;&colon;&colon; select&lowbar;on&lowbar;container&lowbar;copy&lowbar;construction(original&period;get&lowbar;allocator())&apos; to supply memory&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:bsl/basic_string-0faf/2constructor-0f.adoc[basic&lowbar;string](xref:bsl/basic_string-0faf.adoc[basic&lowbar;string] const& original);
----

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

A string cannot be constructed from a `nullptr` or from a literal `0`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:bsl/basic_string-0faf/2constructor-09e.adoc[basic&lowbar;string](xref:bsl/nullptr_t-08.adoc[bsl::nullptr&lowbar;t]) = delete;
----

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

Create a string that has the same value as the specified `original` string by moving (in constant time) the contents of `original` to the new string&period; The allocator associated with `original` is propagated for use in the newly&hyphen;created string&period; `original` is left in a valid but unspecified state&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:bsl/basic_string-0faf/2constructor-09b.adoc[basic&lowbar;string](xref:BloombergLP/bslmf/MovableRef.adoc[BloombergLP::bslmf::MovableRef&lt;basic&lowbar;string&gt;] original) noexcept;
----

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

Create an empty string&period; Optionally specify the `basicAllocator` used to supply memory&period; If `basicAllocator` is not specified, a default&hyphen;constructed allocator is used&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
explicit
xref:bsl/basic_string-0faf/2constructor-00e.adoc[basic&lowbar;string](ALLOCATOR const& basicAllocator) noexcept;
----

[.small]#xref:bsl/basic_string-0faf/2constructor-00e.adoc[_» more&period;&period;&period;_]#

Create a string that has the same value as the specified `object`&period; Optionally specify a `basicAllocator` used to supply memory&period; If `basicAllocator` is not specified, then a default&hyphen;constructed allocator is used&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class STRING&lowbar;VIEW&lowbar;LIKE&lowbar;TYPE&gt;
explicit
xref:bsl/basic_string-0faf/2constructor-098.adoc[basic&lowbar;string](STRING&lowbar;VIEW&lowbar;LIKE&lowbar;TYPE const& object);
----

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

Create a string that has the same value as the specified `original` string that uses the specified `basicAllocator` to supply memory&period; The contents of `original` are moved (in constant time) to the new string if `basicAllocator &equals;&equals; original&period;get&lowbar;allocator()`, and are copied (in linear time) using `basicAllocator` otherwise&period; `original` is left in a valid but unspecified state&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:bsl/basic_string-0faf/2constructor-05c.adoc[basic&lowbar;string](
    xref:BloombergLP/bslmf/MovableRef.adoc[BloombergLP::bslmf::MovableRef&lt;basic&lowbar;string&gt;] original,
    ALLOCATOR const& basicAllocator);
----

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

Create a string and insert (in order) each `CHAR&lowbar;TYPE` object in the specified `values` initializer list&period; Optionally specify a `basicAllocator` used to supply memory&period; If `basicAllocator` is not specified, then a default&hyphen;constructed allocator is used&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:bsl/basic_string-0faf/2constructor-0c13.adoc[basic&lowbar;string](
    std::initializer&lowbar;list&lt;CHAR&lowbar;TYPE&gt; values,
    ALLOCATOR const& basicAllocator = ALLOCATOR());
----

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

Create a string that has the same value as the specified `original` string and uses the specified `basicAllocator` to supply memory&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:bsl/basic_string-0faf/2constructor-004.adoc[basic&lowbar;string](
    xref:bsl/basic_string-0faf.adoc[basic&lowbar;string] const& original,
    ALLOCATOR const& basicAllocator);
----

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

Create a string that has the same value as the specified `strRef` string&period; The resulting string will contain the same sequence of characters as `strRef`&period; Optionally specify a `basicAllocator` used to supply memory&period; If `basicAllocator` is not specified, then a default&hyphen;constructed allocator is used&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:bsl/basic_string-0faf/2constructor-01.adoc[basic&lowbar;string](
    xref:BloombergLP/bslstl/StringRefData-04.adoc[BloombergLP::bslstl::StringRefData&lt;CHAR&lowbar;TYPE&gt;] const& strRef,
    ALLOCATOR const& basicAllocator = ALLOCATOR());
----

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

Same as the constructor taking `const CHAR&lowbar;TYPE &ast;`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;&gt;
requires bsl&colon;&colon;IsStdAllocator&lt;ALLOCATOR&gt;&colon;&colon;value
xref:bsl/basic_string-0faf/2constructor-02.adoc[basic&lowbar;string](
    CHAR&lowbar;TYPE const* characterString,
    ALLOCATOR const& basicAllocator = ALLOCATOR());
----

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

Create a string that has the same value as the specified `original` string, where the type `original` is the string type native to the compiler&apos;s library, instantiated with the same character type and traits type, but not necessarily the same allocator type&period; The resulting string will contain the same sequence of characters as `original`&period; Optionally specify a `basicAllocator` used to supply memory&period; If `basicAllocator` is not specified, then a default&hyphen;constructed allocator is used&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class ALLOC2&gt;
xref:bsl/basic_string-0faf/2constructor-0c0.adoc[basic&lowbar;string](
    std::basic&lowbar;string&lt;CHAR&lowbar;TYPE, CHAR&lowbar;TRAITS, ALLOC2&gt; const& original,
    ALLOCATOR const& basicAllocator = ALLOCATOR());
----

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

Create a string that has the same value as the substring starting at the specified `position` in the specified `original` string&period; Optionally specify the `basicAllocator` used to supply memory&period; If `basicAllocator` is not specified, a default&hyphen;constructed allocator is used&period; The contents of `original` are moved (in constant time) to the new string if `basicAllocator &equals;&equals; original&period;get&lowbar;allocator()`, and are copied (in linear time) using `basicAllocator` otherwise&period; `original` is left in a valid but unspecified state&period; Throw `out&lowbar;of&lowbar;range` if `position &gt; original&period;length()`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:bsl/basic_string-0faf/2constructor-05b.adoc[basic&lowbar;string](
    xref:BloombergLP/bslmf/MovableRef.adoc[BloombergLP::bslmf::MovableRef&lt;basic&lowbar;string&gt;] original,
    xref:bsl/basic_string-0faf/size_type.adoc[size&lowbar;type] position,
    ALLOCATOR const& basicAllocator = ALLOCATOR());
----

[.small]#xref:bsl/basic_string-0faf/2constructor-05b.adoc[_» more&period;&period;&period;_]#

Create a string that has the same value as the substring of the specified `numChars` length starting at the specified `position` in the specified `original` string&period; Optionally specify the `basicAllocator` used to supply memory&period; If `basicAllocator` is not specified, a default&hyphen;constructed allocator is used&period; Throw `out&lowbar;of&lowbar;range` if `position &gt; original&period;length()`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:bsl/basic_string-0faf/2constructor-08d.adoc[basic&lowbar;string](
    xref:bsl/basic_string-0faf.adoc[basic&lowbar;string] const& original,
    xref:bsl/basic_string-0faf/size_type.adoc[size&lowbar;type] position,
    ALLOCATOR const& basicAllocator = ALLOCATOR());
----

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

Create a string that has the same value as the substring of the optionally specified `numChars` length starting at the beginning of the specified `characterString`&period; If `numChars` is not specified, `CHAR&lowbar;TRAITS&colon;&colon;length(characterString)` is used&period; Optionally specify the `basicAllocator` used to supply memory&period; If `basicAllocator` is not specified, a default&hyphen;constructed allocator is used&period; Throw `out&lowbar;of&lowbar;range` if `numChars &gt;&equals; npos`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:bsl/basic_string-0faf/2constructor-06.adoc[basic&lowbar;string](
    CHAR&lowbar;TYPE const* characterString,
    xref:bsl/basic_string-0faf/size_type.adoc[size&lowbar;type] numChars,
    ALLOCATOR const& basicAllocator = ALLOCATOR());
----

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

Same as the constructor taking `(numChars, character)`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;&gt;
requires bsl&colon;&colon;IsStdAllocator&lt;ALLOCATOR&gt;&colon;&colon;value
xref:bsl/basic_string-0faf/2constructor-0de.adoc[basic&lowbar;string](
    xref:bsl/basic_string-0faf/size_type.adoc[size&lowbar;type] numChars,
    CHAR&lowbar;TYPE character,
    ALLOCATOR const& basicAllocator = ALLOCATOR());
----

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

Create a string from 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`&period; Optionally specify a `basicAllocator` used to supply memory&period; If `basicAllocator` is not specified, a default&hyphen;constructed allocator is used&period; The behavior is undefined unless `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-0faf/2constructor-080.adoc[basic&lowbar;string](
    INPUT&lowbar;ITER first,
    INPUT&lowbar;ITER last,
    ALLOCATOR const& basicAllocator = ALLOCATOR());
----

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

Create a string that containing the characters from the specified `range`&period; Optionally specify a `basicAllocator` used to supply memory&period; If `basicAllocator` is not specified, a default&hyphen;constructed allocator is used&period; Note that `range` must meet the requirements of an input range and the values from `range` must have a type matching or convertible to (template parameter) `CHAR&lowbar;TYPE`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class RANGE&gt;
xref:bsl/basic_string-0faf/2constructor-07.adoc[basic&lowbar;string](
    std::from&lowbar;range&lowbar;t,
    RANGE&& range,
    ALLOCATOR const& basicAllocator = ALLOCATOR());
----

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

Create a string that has the same value as the substring of the specified `numChars` length starting at the specified `position` in the specified `original` string&period; If `numChars` is more than the available string length, then the remaining length of the string is used (i&period;e&period;, `numChars` is set to `original&period;length() &hyphen; position`)&period; Optionally specify the `basicAllocator` used to supply memory&period; If `basicAllocator` is not specified, a default&hyphen;constructed allocator is used&period; The contents of `original` are moved (in constant time) to the new string if `basicAllocator &equals;&equals; original&period;get&lowbar;allocator()`, and are copied (in linear time) using `basicAllocator` otherwise&period; `original` is left in a valid but unspecified state&period; Throw `out&lowbar;of&lowbar;range` if `position &gt; original&period;length()`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:bsl/basic_string-0faf/2constructor-0b.adoc[basic&lowbar;string](
    xref:BloombergLP/bslmf/MovableRef.adoc[BloombergLP::bslmf::MovableRef&lt;basic&lowbar;string&gt;] original,
    xref:bsl/basic_string-0faf/size_type.adoc[size&lowbar;type] position,
    xref:bsl/basic_string-0faf/size_type.adoc[size&lowbar;type] numChars,
    ALLOCATOR const& basicAllocator = ALLOCATOR());
----

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

Create a string that has the same value as the substring of the specified `numChars` length starting at the specified `position` in the specified `original` string&period; If `numChars` equals `npos`, then the remaining length of the string is used (i&period;e&period;, `numChars` is set to `original&period;length() &hyphen; position`)&period; Optionally specify the `basicAllocator` used to supply memory&period; If `basicAllocator` is not specified, a default&hyphen;constructed allocator is used&period; Throw `out&lowbar;of&lowbar;range` if `position &gt; original&period;length()`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:bsl/basic_string-0faf/2constructor-0c1b.adoc[basic&lowbar;string](
    xref:bsl/basic_string-0faf.adoc[basic&lowbar;string] const& original,
    xref:bsl/basic_string-0faf/size_type.adoc[size&lowbar;type] position,
    xref:bsl/basic_string-0faf/size_type.adoc[size&lowbar;type] numChars,
    ALLOCATOR const& basicAllocator = ALLOCATOR());
----

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

Create a string that has the same value as the substring of the specified `numChars` length starting at the specified `position` in the specified `object`&period; Optionally specify a `basicAllocator` used to supply memory&period; If the `basicAllocator` is not specified, a default&hyphen;constructed allocator is used&period; Throw `out&lowbar;of&lowbar;range` if `position &gt; original&period;object()`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class STRING&lowbar;VIEW&lowbar;LIKE&lowbar;TYPE&gt;
xref:bsl/basic_string-0faf/2constructor-0ea.adoc[basic&lowbar;string](
    STRING&lowbar;VIEW&lowbar;LIKE&lowbar;TYPE const& object,
    xref:bsl/basic_string-0faf/size_type.adoc[size&lowbar;type] position,
    xref:bsl/basic_string-0faf/size_type.adoc[size&lowbar;type] numChars,
    ALLOCATOR const& basicAllocator = ALLOCATOR());
----

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


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