diff --git a/lexical_cast.htm b/lexical_cast.htm index efc7219..5457a33 100644 --- a/lexical_cast.htm +++ b/lexical_cast.htm @@ -245,6 +245,15 @@ Eliminate an overhead of std::locale if your program runs in the "C May be in a future version. There is no requirement in [N1973] to reset the flag but remember that [N1973] is not yet accepted by the committee. By the way, it's a great opportunity to make your operator>> conform to the standard. Read a good C++ book, study std::sentry and ios_state_saver. + + Question: + Why std::cout << boost::lexical_cast<unsigned int>("-1"); does not throw, but outputs 4294967295? + + + Answer: + boost::lexical_cast has the behavior of stringstream, which uses num_get functions of std::locale to convert numbers. If we look at the [22.2.2.1.2] of Programming languages — C++, we'll see, that num_get uses the rules of scanf for conversions. And in the C99 standard for unsigned input value minus sign is optional, so if a negative number is read, no errors will arise and the result will be the two's complement. + +

References