public member function
std::string::operator+=
<string>
string& operator+= ( const string& str );
string& operator+= ( const char* s );
string& operator+= ( char c );
Append to string
Appends a copy of the argument to the string.
The new string content is the content existing in the string object before the call followed by the content of the argument.
The
append member function provides a similar functionality with additional options.
Parameters
- str
- string object. A copy of the content of this object is appended to the object's content.
- s
- A pointer to an array containing a null-terminated character sequence (C string), which is appended to the object's content.
- c
- Character. This single character is appended to the string object's content.
Return Value
*this
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
// string::operator+=
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string name ("John");
string family ("Smith");
name += " K. "; // c-string
name += family; // string
name += '\n'; // character
cout << name;
return 0;
}
|
Output:
Basic template member declarations
( basic_string<charT,traits,Allocator> )
1 2 3 4 5
|
basic_string<charT,traits,Allocator>&
operator+= ( const basic_string<charT,traits,Allocator>& str );
basic_string<charT,traits,Allocator>&
operator+= ( const charT* s );
basic_string<charT,traits,Allocator>& operator+= ( char c );
|
See also
- string::append
- Append to string (public member function)
- string::assign
- Assign content to string (public member function)
- string::operator=
- String assignment (public member function)
- string::insert
- Insert into string (public member function)
- string::replace
- Replace part of string (public member function)