Value stored when istream read fails

后端 未结 2 1384
抹茶落季
抹茶落季 2021-01-22 20:23

Sample code:

#include 

int main()
{
    int x = 5;
    std::cin >> x;
    std::cout << x << \'\\n\';
}

On on

2条回答
  •  后悔当初
    2021-01-22 21:24

    Yes, this is the correct behaviour since C++11.

    • istream behavior change in C++ upon failure

    The difference in what you're seeing is that a zero is written "when extraction fails", but extraction is not even attempted if EOF is already set on the stream… so nothing happens.

提交回复
热议问题