I/O 流标志如何工作?

How does the I/O stream flags work?

我正在从 LearnCpp 网站上学习,我遇到了这一行 "If an error occurs and a stream is set to anything other than goodbit, further stream operations on that stream will be ignored. This condition can be cleared by calling the clear() function"。但是在 ios_base class 中,我注意到标志设置为静态,这意味着它们由 class 的每个实例共享,这是否意味着如果例如 cin 设置为将 fatalbit 标志设置为 true istream class 的所有其他实例将不起作用?

标志本身没有改变,它们是静态常量。改变的是每个标准流中存在的底层位掩码。 clear() 所做的是重置掩码并设置提供的标志(ios_base::goodbit 我的默认值)。