This is a char type, not a constant string. First, according to the priority, the following '0'+'a' will be calculated first. For the char type, the addition is still a char type ('a'), so += Char type, only one character is actually appended.
¦ /**
¦ * @brief Append a character.
¦ * @param c The character to append.
¦ * @return Reference to this string.
¦ */
¦ basic_string&
¦ operator+=(_CharT __c)
¦ {
this->push_back(__c);
return *this;
¦ }
This is because: the former is done first'
And the latter appends two characters.The reason for the new error you posted is that 'a' = 97
97 + 97 = 194exceeds the range of 0-127 ascii characters, so it is implicitly converted from a numerical value to a character report warning
This is a char type, not a constant string. First, according to the priority, the following '0'+'a' will be calculated first. For the char type, the addition is still a char type ('a'), so += Char type, only one character is actually appended.
Please do not send screenshots when sending codes.
This is because (1) the operator precedence is different,
+
is higher than+=
; (2) the operands of addition are different.is equivalent to
rrreeeSimilar to
rrreeeis equivalent to
rrreeeAdding two variables (characters) of type
char
is equivalent to adding the values corresponding to the two characters, so'
'0' + 'a' gets a new character, so this is equivalent to: