c++ - Issue with string::operator+= -
i tried append 2 letters string, seems string not changed:
void fun() { string str; str += 'a' + 'b'; cout << str; }
i checked source code of stl , found implementation of operator+=
, still don't know why.
basic_string& operator+=(_chart __c) { this->push_back(__c); return *this; }
by adding 'a' + 'b'
have 2 chars added form char. add string +=
.
this code want:
std::string str; ( str += 'a' ) += 'b'; std::cout << str;
Comments
Post a Comment