且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C / C ++的预期行为

更新时间:2023-11-01 11:59:28

简短的回答是,在检测到无效输入时, cin (这是一个 istream )设置其失败状态位,导致进一步的输入被忽略,直到流的错误被清除。这根本不是意料之外的。它永远属于标准行为的一部分。
The short answer is that, on detecting invalid input, cin (which is an istream) sets its fail status bit, causing further input to be ignored until the stream's error is cleared. This is not unexpected at all. It's been part of the standard behaviour since forever.