gpt4 book ai didi

c++ - 是否保证标准提取运算符>>在失败的情况下不会更改参数?

转载 作者:太空宇宙 更新时间:2023-11-03 10:24:52 24 4
gpt4 key购买 nike

如果调用input_stream >> i;,其中i是算术类型,抛出异常或设置badbit等,是否保证i没有改变?

最佳答案

在 C++11 之前,该值保持原样,[reference] :

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)

但在 C++11 之后,没有。它设置为 0如果提取失败(相同的引用):

If extraction fails, zero is written to value and failbit is set. If extraction results in the value too large or too small to fit in value, std::numeric_limits<T>::max() or std::numeric_limits<T>::min() is written and failbit flag is set. (since C++11)

关于c++ - 是否保证标准提取运算符>>在失败的情况下不会更改参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40828481/

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