The second and third job because of this constructor:
basic_string( std::initializer_list<CharT> init, const Allocator& alloc = Allocator() );
That is, whenever the compiler sees curly braces, it converts {...} to std::initializer_list<T> for a suitable T.
In your case, it is converted to std::initializer_list<char> , which is then passed to the aforementioned constructor std::string .
Since there is an overload += that takes std::initializer_list<char> :
basic_string& operator+=( std::initializer_list<CharT> ilist );
you can write this:
std::string s; s += {65}; s += {66, 67};
That should work too.
Note that you can also write this:
s += 65;
Even this will work, but for another reason - it causes the following overload:
basic_string& operator+=( CharT ch );
In this case, 65 (which is int ) is converted to type char .
Hope this helps.
source share