$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
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.