std::basic_string<CharT,Traits,Allocator>::operator+= (3) - Linux Man Pages
basic_string& operator+=( const basic_string& str ); (1)
basic_string& operator+=( CharT ch ); (2)
basic_string& operator+=( const CharT* s ); (3)
basic_string& operator+=( std::initializer_list<CharT> ilist ); (4) (since C++11)
template < class T > (5) (since C++17)
basic_string& operator+=( const T& t );
Appends additional characters to the string.
1) Appends string str
2) Appends character ch
3) Appends the null-terminated character string pointed to by s.
4) Appends characters in the initializer list ilist.
5) Implicitly converts t to a string view sv as if by std::basic_string_view<CharT, Traits> sv = t;, then appends characters in the string view sv as if by append(sv). This overload only participates in overload resolution if std::is_convertible_v<const T&, std::basic_string_view<CharT, Traits>> is true and std::is_convertible_v<const T&, const CharT*> is false.
str - string to append
ch - character value to append
s - pointer to a null-terminated character string to append
ilist - std::initializer_list with the characters to append
t - object (convertible to std::basic_string_view) with the characters to append
1) linear in size of str
3) linear in size of s
4) linear in size of ilist
If an exception is thrown for any reason, this function has no effect (strong exception guarantee).
If the operation would result in size() > max_size(), throws std::length_error.
Overload (2) can accept any types that are implicitly convertible to CharT. For std::string, where CharT is char, the set of acceptable types includes all arithmetic types. This may have unintended effects.
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR Applied to Behavior as published Correct behavior
LWG_2946 C++17 string_view overload causes ambiguity in some cases avoided by making it a template
// Run this code