The following code compiles in Visual Studio 2008 but fails in Visual Studio 2013 and later.
std::string str("foo");
std::stringstream ss(str);
float f = 0;
if ((ss >> f) == false)
std::cout << "Parse error
";
The error message is
error C2678: binary '==' : no operator found which takes a left-hand
operand of type 'std::basic_istream>' (or
there is no acceptable conversion)
and is successfully fixed by changing as follows:
if (!(ss >> f))
std::cout << "Parse error
";
I'm not understanding this well. My question is, what operator or cast or maybe ios
flags are involved that allow the stream read to be evaluated as a boolean in the first place, and then why does the lack of an operator==
break it?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…