
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