- Reference
- <string>
- basic_string
- operator+
function template
<string>
std::operator+ (basic_string)
| string (1) | template <class charT, class traits, class Alloc> basic_string operator+ (const basic_string<charT,traits,Alloc>& lhs, const basic_string<charT,traits,Alloc>& rhs); |
|---|---|
| c-string (2) | template <class charT, class traits, class Alloc> basic_string operator+ (const basic_string<charT,traits,Alloc>& lhs, const charT* rhs);template <class charT, class traits, class Alloc> basic_string operator+ (const charT* lhs, const basic_string<charT,traits,Alloc>& rhs); |
| character (3) | template <class charT, class traits, class Alloc> basic_string operator+ (const basic_string<charT,traits,Alloc>& lhs, charT rhs);template <class charT, class traits, class Alloc> basic_string operator+ (charT lhs, const basic_string<charT,traits,Alloc>& rhs); |
| string (1) | template <class charT, class traits, class Alloc> basic_string operator+ (const basic_string<charT,traits,Alloc>& lhs, const basic_string<charT,traits,Alloc>& rhs);template <class charT, class traits, class Alloc> basic_string operator+ (basic_string<charT,traits,Alloc>&& lhs, basic_string<charT,traits,Alloc>&& rhs);template <class charT, class traits, class Alloc> basic_string operator+ (basic_string<charT,traits,Alloc>&& lhs, const basic_string<charT,traits,Alloc>& rhs);template <class charT, class traits, class Alloc> basic_string operator+ (const basic_string<charT,traits,Alloc>& lhs, basic_string<charT,traits,Alloc>&& rhs); |
|---|---|
| c-string (2) | template <class charT, class traits, class Alloc> basic_string operator+ (const basic_string<charT,traits,Alloc>& lhs, const charT* rhs);template <class charT, class traits, class Alloc> basic_string operator+ (basic_string<charT,traits,Alloc>&& lhs, const charT* rhs);template <class charT, class traits, class Alloc> basic_string operator+ (const charT* lhs, const basic_string<charT,traits,Alloc>& rhs);template <class charT, class traits, class Alloc> basic_string operator+ (const charT* lhs, basic_string<charT,traits,Alloc>&& rhs); |
| character (3) | template <class charT, class traits, class Alloc> basic_string operator+ (const basic_string<charT,traits,Alloc>& lhs, charT rhs);template <class charT, class traits, class Alloc> basic_string operator+ (basic_string<charT,traits,Alloc>&& lhs, charT rhs);template <class charT, class traits, class Alloc> basic_string operator+ (charT lhs, const basic_string<charT,traits,Alloc>& rhs);template <class charT, class traits, class Alloc> basic_string operator+ (charT lhs, basic_string<charT,traits,Alloc>&& rhs); |
Concatenate strings
In the signatures taking at least one rvalue reference as argument, the returned object is move-constructed by passing this argument, which is left in an unspecified but valid state. If both arguments are rvalue references, only one of them is moved (it is unspecified which), with the other one preserving its value.
Parameters
- lhs, rhs
- Arguments to the left- and right-hand side of the operator, respectively.
If of type charT*, it shall point to a null-terminated character sequence.
charT is basic_string's character type (i.e., its first template parameter).
Example
|
|
Output:
Return Value
A basic_string object whose value is the concatenation of lhs and rhs.Complexity
Unspecified, but generally linear in the resulting string length (and linear in the length of the non-moved argument for signatures with rvalue references).Iterator validity
The signatures with rvalue references may invalidate iterators, pointers and references related to the moved basic_string object.Data races
The signatures with rvalue references modify the moved basic_string object.Exception safety
Strong guarantee: if an exception is thrown, there are no changes in either basic_string objects.If
s is not a null-terminated character sequence, it causes undefined behavior.
If the resulting string length would exceed the max_size, a length_error exception is thrown.
If the type uses the default allocator, a bad_alloc exception is thrown if the function needs to allocate storage and fails.
See also
- basic_string::append
- Append to string (public member function)
- basic_string::insert
- Insert into string (public member function)
- basic_string::operator+=
- Append to string (public member function)