我有這樣的代碼行爲古怪:String類賦值運算符(+ =)的行爲古怪
int main() {
string a = "TRY";
string b = "THIS";
a += b[0] + '!'; //This outputs "TRYu"?
//a = a + b[0] + '!'; //This outputs "TRYT!" as expected.
cout << a;
}
應該不是上面的兩個語句是一樣的嗎?
想想'b [0] +'!''是幹什麼的。 – chris
http://en.cppreference.com/w/cpp/language/operator_precedence –