What would this return?
boost::lexical_cast<float>("-2");
I am not able to find a lexical_cast conversion from string to float example in the documentation.
Thanks
What would this return?
boost::lexical_cast<float>("-2");
I am not able to find a lexical_cast conversion from string to float example in the documentation.
Thanks
This:
float value = boost::lexical_cast<float>("-2");
Is basically equivalent to this:
float value;
{
std::stringstream ss;
ss << "-2";
ss >> value;
}
Of course, Boost's lexical_cast does a few other things behind the scenes, and handles errors with exceptions rather than iostream error states, but for the most part, if a conversion through a std::stringstring will work, boost::lexical_cast will work the same way.
The value of the float is, of course, -2.0f
.