Boost logo

Boost Users :

Subject: Re: [Boost-users] [BGL] Encountering "bad lexical cast" exception when reading a class from graphviz file
From: Nicholas Mario Wardhana (mario.wardhana_at_[hidden])
Date: 2012-07-21 15:24:10


On 22 July 2012 02:43, Jeremiah Willcock <jewillco_at_[hidden]> wrote:
>
>
> Can you do lexical_cast<Point>("1 2 3")? If that fails, make sure that
> reading that string as a Point using istringstream reads the entire contents
> of the stream (hits EOF and does not set failbit); I am not good enough with
> streams to know exactly why your code is failing beyond that. If the
> lexical_cast succeeds, there is a bug in BGL's parsing of the string and
> I'll take a look at it further.
>
> -- Jeremiah Willcock
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users

Thanks for your reply, Jeremiah!

I tried lexical_cast<Point>("1 2 3") and it fails with the same exception too.

As for the istringstream part, my code is

std::istringstream iStringStream("1");
Point p2;
std::istream& returnValue = iStringStream >> p2;
std::cout << "Does it reach EOF? " << (returnValue.eof()? "yes" :
"no") << std::endl;
std::cout << "Is it bad? " << (returnValue.bad()? "yes" : "no") << std::endl;
std::cout << "Does it fail? " << (returnValue.fail()? "yes" : "no") <<
std::endl;
std::cout << "Is it good? " << (returnValue.good()? "yes" : "no") << std::endl;

This is what it prints.

Does it reach EOF? yes
Is it bad? no
Does it fail? yes
Is it good? no

So, I suppose the stream reaches EOF, and it is not bad, but it fails,
and therefore it is not good. I wonder that these mean? I think I'll
search more about that...

Thanks again.

Best regards,
Nicholas


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