|
Boost Users : |
From: Yuval Ronen (ronen_yuval_at_[hidden])
Date: 2005-01-19 01:53:18
> For 2, It seems more like a problem with stringstream - I think
> lexical_cast does:
>
> stringstream ss;
> ss << input;
> ss >> output;
> return output;
Not quite. In lexical_cast there's a code to specifically *not* ignore
leading whitespace - look for for the line
'stream.unsetf(std::ios::skipws)'. It also contains a code to
specifically *ignore* trailing whitespace (but not other characters) -
look for 'stream >> std::ws'. So this was done intentionally, even
though mistakenly in my opinion.
My version of 'lexical_cast<T, string>' looks like (I hope I remember
correctly):
template <typename T>
T convert_from_string(const string &str)
{
T val;
istringstream iss(str);
iss >> noskipws >> val;
if (iss.fail() || !iss.eof())
throw ...;
return val;
}
and it works fine. No problems with the stringstream.
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