gpt4 book ai didi

c++ - std::stringstream 中可能出现的错误是什么(设置 failbit 和 badbit 的方法)?

转载 作者:搜寻专家 更新时间:2023-10-31 01:02:58 33 4
gpt4 key购买 nike

std::stringstream 中可能出现的错误是什么?

具体来说,std::stringstream 派生自 std::ios,这意味着它有一个 std::ios::rdstate。在 std::ios::rdstate 中,当 failbitbadbit 被设置时,我们会遇到问题。因此,在 std::stringstream 中设置 failbitbadbit 的可能方法是什么?

设置failbitbadbit 的方法是依赖于编译器/实现还是由标准指定?

最佳答案

C++11 中的表 124 指定了各个位的含义:

badbit indicates a loss of integrity in an input or output sequence (such as an irrecoverable read error from a file);

eofbit indicates that an input operation reached the end of an input sequence;

failbit indicates that an input operation failed to read the expected characters, or that an output operation failed to generate the desired characters.

至于哪些操作设置这些位,散布在标准的各个地方,您可以搜索掩码的出现以找出设置和清除它的内容。

例如,可以设置 badbit 的一种方法是,如果您在 operator>> 调用期间使用 get exception 。这在 27.7.2.2 格式化输入函数 中有详细说明。整个标准中还有许多其他地方给出了类似的描述。

关于c++ - std::stringstream 中可能出现的错误是什么(设置 failbit 和 badbit 的方法)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26228985/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com