Difference between adding a C ++ line and the + = operator
Is there a noticeable difference between the two lines? A colleague of mine says that using + = is "faster", but I don't understand why they should be different:
string s1 = "hello";
string s2 = " world";
// Option 1
s1 += s2;
// Option 2
s1.append(s2);
To clarify, I am not asking about the differences in use between the two functions. I know what append()
can be used for a wider range of uses and what is operator +=
somewhat more specialized. I am worried about how this particular example is handled.
+3
source to share
2 answers
As per the standard regarding string :: op + = / on-line C ++ standard project , I wouldn't expect any difference:
basic_string & operator + = (const basic_string & str);
(1) Effects: calls to append (str).
(2) Returns: * this.
+6
source to share