BOOST WIKI | RecentChanges | Preferences | Page List | Links List
A nice addition would be a to_string which would not stop parsing when hitting white space of a string. Take a look at the following discussion threads on this topic.
Personally I use this in my c++ wrapper around libxml2 for convenience of putting data types into my attributes or data of nodes.
- If the input is a string, it must not be empty and it must not have spaces. At some point in the future, there will be a string -> string specialization which may help you with this problem.
- I think it's okay to have spaces in the string, if the spaces will be eaten by the casted - to type's operator<<. This isn't true for any of the built-in types, of course, but it might be true for user classes. Extra spaces (or any other chars) on the end are no-nos, though.
I (People/Jeff Garland) have also used lexical cast for xml related conversions. A number of us have run across some edges with this library.
One issue with the library is the handling of doubles being truncated due to the default precision setting of the stream. This doesn't throw an exception, but doesn't give the right correct result either.
double d = lexical_cast<double>(s); //oops truncated due to precision of std::stringstream
You can see this message for more discussion
Disclaimer: This site not officially maintained by Boost Developers