|
Boost Users : |
From: Ben Hutchings (ben.hutchings_at_[hidden])
Date: 2005-03-29 06:50:02
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 <boost/lexical_cast.hpp>
>
> int main(int argc, char* argv[])
> {
> double d = std::numeric_limits<double>::infinity();
> std::string s = boost::lexical_cast<std::string>(d);
> std::cout<<d<<", "<<s<<std::endl;
>
> //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.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net