The last line of the following program throws a bad_lexical_cast exception. The
code is compiled with VC7.1.
//**********************************************************
#include <limits>
#include <iostream>
#include
Patrick Mézard wrote:
The last line of the following program throws a bad_lexical_cast exception. The code is compiled with VC7.1.
//********************************************************** #include <limits> #include <iostream> #include
int main(int argc, char* argv[]) { double d = std::numeric_limits<double>::infinity(); std::string s = boost::lexical_caststd::string(d); std::cout<
//Throws bad_lexical_cast boost::lexical_cast<double>(s); } //**********************************************************
The output is:
"1.#INF, 1.#INF"
Am I doing something wrong ?
Textual representations of infinities and NaNs are not specified in the C++ standard or the C90 standard which it references (though they are in C99). So there is unfortunately no guarantee that you can successfully convert them to and from strings. Ben.
participants (2)
-
Ben Hutchings
-
Patrick Mézard