On this page
std::operator+(std::basic_string)
Defined in header <string> |
||
---|---|---|
|
(1) | (constexpr since C++20) |
|
(2) | (constexpr since C++20) |
|
(3) | (constexpr since C++20) |
|
(4) | (constexpr since C++20) |
|
(5) | (constexpr since C++20) |
|
(6) | (since C++11) (constexpr since C++20) |
|
(7) | (since C++11) (constexpr since C++20) |
|
(8) | (since C++11) (constexpr since C++20) |
|
(9) | (since C++11) (constexpr since C++20) |
|
(10) | (since C++11) (constexpr since C++20) |
|
(11) | (since C++11) (constexpr since C++20) |
|
(12) | (since C++11) (constexpr since C++20) |
Returns a string containing characters from lhs
followed by the characters from rhs
.
The allocator used for the result is: 1-3)std::allocator_traits<Alloc>::select_on_container_copy_construction(lhs.get_allocator()) 4,5) std::allocator_traits<Alloc>::select_on_container_copy_construction(rhs.get_allocator()) 6-9) lhs.get_allocator() 10-12) rhs.get_allocator() In other words, if one operand is a For (6-12), all rvalue |
(since C++11) |
Parameters
lhs | - | string, character, or pointer to the first character in a null-terminated array |
rhs | - | string, character, or pointer to the first character in a null-terminated array |
Return value
A string containing characters from lhs
followed by the characters from rhs
, using the allocator determined as above(since C++11).
Notes
Because the allocator used by the result of
For a chain of
For better and portable control over allocators, member functions like |
(since C++11) |
Example
#include <iostream>
#include <string>
int main()
{
std::string s1 = "Hello";
std::string s2 = "world";
std::cout << s1 + ' ' + s2 + "!\n";
}
Output:
Hello world!
Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR | Applied to | Behavior as published | Correct behavior |
---|---|---|---|
P1165R1 | C++11 | allocator propagation is haphazard and inconsistent | made more consistent |
See also
appends characters to the end (public member function) |
|
appends characters to the end (public member function) |
|
inserts characters (public member function) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/string/basic_string/operator%2B