jjzjj

convertedValue

全部标签

c++ - 为什么在成功将 bool 字符串值转换为 bool 值时,istringstream eof 标志没有变为真?

我正在学习如何使用istringstream将存储为字符串的值转换为native类型。当存储为字符串的数字成功转换为int或double时,istringstreameof()函数返回true。当存储为字符串的bool值成功转换为bool时,eof()返回false。造成差异的原因是什么?为什么当似乎没有其他字符需要处理时eof()不返回true?转换为bool值的代码:stringvalue="true";istringstreamconverter(value);boolconvertedValue;if(!(converter>>std::boolalpha>>converted