string::replace

Replace a substring with a string.

Synopsis

string&
replace(
    std::size_t pos,
    std::size_t count,
    string_view sv); (1)

string&
replace(
    string::const_iterator first,
    string::const_iterator last,
    string_view sv); (2)

template<
    class InputIt>
string&
replace(
    string::const_iterator first,
    string::const_iterator last,
    InputIt first2,
    InputIt last2); (3)

string&
replace(
    std::size_t pos,
    std::size_t count,
    std::size_t count2,
    char ch); (4)

string&
replace(
    string::const_iterator first,
    string::const_iterator last,
    std::size_t count,
    char ch); (5)

Description

Replaces rcount characters starting at index pos with those of sv, where rcount is std::min(count, size() - pos).

Exception Safety

Strong guarantee.

All references, pointers, or iterators referring to contained elements are invalidated. Any past-the-end iterators are also invalidated.

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

Parameters

Name Description

pos

The index to replace at.

count

The number of characters to replace.

sv

The string_view to replace with.

first

An iterator referring to the first character to replace.

last

An iterator one past the end of the last character to replace.

first2

An iterator referring to the first character to replace with.

last2

An iterator one past the end of the last character to replace with.

count2

The number of characters to replace with.

ch

The character to replace with.

Exceptions

Type Thrown On

boost::system::system_error

size() + (sv.size() - rcount) > max_size().