Difference between c++ string append and operator +=
In Microsoft STL implementation, the operator +=
is an inline function, which calls append()
. Here are the implementations,
- string (1):
string& operator+= (const string& str)
basic_string& operator+=(const basic_string& _Right) {
return append(_Right);
}
- c-string (2):
string& operator+= (const char* s)
basic_string& operator+=(_In_z_ const _Elem* const _Ptr) {
return append(_Ptr);
}
- character (3):
string& operator+= (char c)
basic_string& operator+=(_Elem _Ch) {
push_back(_Ch);
return *this;
}
- Source: GitHub: Microsoft/STL
According to the standard concerning string::op+= / online c++ standard draft, I wouldn't expect any difference:
basic_string& operator+=(const basic_string& str);
(1) Effects: Calls append(str).
(2) Returns: *this.