You're declaring a
as an int
, then the operator>>
expects digits, but you give a punctuation, which makes extraction fails. As the result, since C++11, a
is set to 0
; before C++11 a
won't be modified.
If extraction fails (e.g. if a letter was entered where a digit is expected), value is left unmodified and failbit is set. (until C++11)
If extraction fails, zero is written to value and failbit is set. (since C++11)
And
I expected it to print out the equivalent ASCII number.
No, even for valid digits, e.g. if you input 1
, a
will be set with value 1
, but not its ASCII number, i.e. 49
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…