Namespaces
Variants
Actions

std::basic_string<CharT,Traits,Allocator>::assign

From cppreference.com
< cpp‎ | string‎ | basic string
 
 
 
std::basic_string
 
basic_string& assign( const basic_string& str );
(1) (constexpr since C++20)
basic_string& assign( basic_string&& str ) noexcept(/* see below */);
(2) (since C++11)
(constexpr since C++20)
basic_string& assign( size_type count, CharT ch );
(3) (constexpr since C++20)
basic_string& assign( const CharT* s, size_type count );
(4) (constexpr since C++20)
basic_string& assign( const CharT* s );
(5) (constexpr since C++20)
template< class SV >
basic_string& assign( const SV& t );
(6) (since C++17)
(constexpr since C++20)
template< class SV >

basic_string& assign( const SV& t,

                      size_type pos, size_type count = npos);
(7) (since C++17)
(constexpr since C++20)
(8)
basic_string& assign( const basic_string& str,
                      size_type pos, size_type count );
(until C++14)
basic_string& assign( const basic_string& str,
                      size_type pos, size_type count = npos);
(since C++14)
(constexpr since C++20)
template< class InputIt >
basic_string& assign( InputIt first, InputIt last );
(9) (constexpr since C++20)
basic_string& assign( std::initializer_list<CharT> ilist );
(10) (since C++11)
(constexpr since C++20)

Replaces the contents of the string.

1) Equivalent to return *this = str;.
2) Equivalent to return *this = std::move(str);.
3) Replaces the contents with count copies of character ch.
Equivalent to clear(); resize(n, c); return *this;.
4) Replaces the contents with copies of the characters in the range [ss + count).
If [ss + count) is not a valid range, the behavior is undefined.
5) Equivalent to return assign(s, Traits::length(s));.
6,7) Replaces the contents with characters in a string view sv constructed from t.
  • If only t is provided, replaces the contents with all characters in sv.
  • If pos is also provided:
    • If count is npos, replaces the contents with all characters in sv starting from pos.
    • Otherwise, replaces the contents with the std::min(count, sv.size() - pos) characters in sv starting from pos.
These overloads participate in overload resolution only if all following conditions are satisfied: