Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r71922 - trunk/libs/conversion
From: antoshkka_at_[hidden]
Date: 2011-05-13 13:31:17

Author: apolukhin
Date: 2011-05-13 13:31:16 EDT (Fri, 13 May 2011)
New Revision: 71922

Added documentation on the feature, described in ticket. Fixed 5494
Text files modified:
   trunk/libs/conversion/lexical_cast.htm | 9 +++++++++
   1 files changed, 9 insertions(+), 0 deletions(-)

Modified: trunk/libs/conversion/lexical_cast.htm
--- trunk/libs/conversion/lexical_cast.htm (original)
+++ trunk/libs/conversion/lexical_cast.htm 2011-05-13 13:31:16 EDT (Fri, 13 May 2011)
@@ -245,6 +245,15 @@
     <td>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 <code>operator&gt;&gt;</code> conform to the standard. Read a good C++ book, study <code>std::sentry</code> and ios_state_saver.
+ <tr>
+ <td valign="top"><b>Question:</b></td>
+ <td>Why <code>std::cout << boost::lexical_cast&lt;unsigned int&gt;("-1");</code> does not throw, but outputs 4294967295?</td>
+ </tr>
+ <tr>
+ <td valign="top"><b>Answer:</b></td>
+ <td><code>boost::lexical_cast</code> has the behavior of <code>stringstream</code>, which uses <code>num_get</code> functions of <code>std::locale</code> to convert numbers. If we look at the [] of Programming languages &mdash; C++, we'll see, that <code>num_get</code> uses the rules of <code>scanf</code> 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.
+ </td>
+ </tr>
 <h2><a name="references">References</a></h2>

Boost-Commit list run by bdawes at, david.abrahams at, gregod at, cpdaniel at, john at