string::assign

Assign characters to a string.

Synopsis

string&
assign(
    std::size_t count,
    char ch); (1)

string&
assign(
    string const& other); (2)

string&
assign(
    string&& other); (3)

string&
assign(
    char const* s,
    std::size_t count); (4)

string&
assign(
    char const* s); (5)

template<
    class InputIt>
string&
assign(
    InputIt first,
    InputIt last); (6)

string&
assign(
    string_view s); (7)

Description

Replace the contents with count copies of character ch.

Complexity

Linear in count.

Exception Safety

Strong guarantee. Calls to memory_resource::allocate may throw.

Template Parameters

Type Description

InputIt

The type of the iterators.

Return Value

*this

Return Value

*this

Return Value

*this

Return Value

*this

Return Value

*this

Return Value

*this

Return Value

*this

Parameters

Name Description

count

The size of the resulting string.

ch

The value to initialize characters of the string with.

other

The string to use as a source to copy from.

s

A pointer to a character string used to copy from.

first

An input iterator pointing to the first character to insert, or pointing to the end of the range.

last

An input iterator pointing to the end of the range.

Exceptions

Type Thrown On

boost::system::system_error

count > max_size().