Issue with string::operator+=

c++, string

Solution

By adding `'a' + 'b'` you will have 2 chars added together to form another char. Then you add it to the string with `+=`.

This code will do what you want:

std::string str;
( str += 'a' ) += 'b';

std::cout << str;

Problem

I tried to append two letters to a string, but it seems that the string is not changed: ``` void fun() { string str; str += 'a' + 'b'; cout << str; } ``` I checked the source code of STL and found the implementation of `operator+=`, but I still don't know why. ``` basic_string& operator+=(_CharT __c) { this->push_back(__c); return *this; } ```

Original source