Boost C++ Libraries: Ticket #1638: allow lexical_cast to handle based number strings https://svn.boost.org/trac10/ticket/1638 <p> This report comes from Debian user "Wesley J. Landaker" &lt;wjl@…&gt; See <a class="ext-link" href="http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=412931"><span class="icon">​</span>http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=412931</a> </p> <p> Please allow lexical_cast to handle based number strings. Currently, it only supports decimal strings, but it should be able to handle octal and hexadecimal strings if they have correct prefix notations. </p> <p> Background: This happens because lexical_cast constructs a stringstream, which by default has the ios_base::dec flag set. If this flag is unset, it will still read decimal strings, but will also automatically determine the base by looking at the prefix, so will read decimal strings if the number starts with 0-9, octal if it starts with 0, and hex if it starts with 0x. </p> <p> Fix: After constructing the stringstream, simply call stringstring::unsetf(std::ios_base::basefield). Because decimal numbers are still handled correctly, this is totally backwards compatible. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/1638 Trac 1.4.3 nasonov Mon, 18 Feb 2008 23:47:23 GMT status, component changed; owner set https://svn.boost.org/trac10/ticket/1638#comment:1 https://svn.boost.org/trac10/ticket/1638#comment:1 <ul> <li><strong>owner</strong> set to <span class="trac-author">nasonov</span> </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">lexical_cast</span> </li> </ul> Ticket nasonov Mon, 18 Feb 2008 23:52:53 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/1638#comment:2 https://svn.boost.org/trac10/ticket/1638#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> <p> This feature is out scope of the library. </p> <p> References: </p> <p> <a class="changeset" href="https://svn.boost.org/trac10/changeset/1" title="Import core sources for SVNmanger 0.38 ">[1]</a> Boost documentation </p> <blockquote> <p> <a href="http://www.boost.org/libs/conversion/lexical_cast.htm#motivation">http://www.boost.org/libs/conversion/lexical_cast.htm#motivation</a> </p> </blockquote> <p> <a class="changeset" href="https://svn.boost.org/trac10/changeset/2" title="Add Boost Disclaimer">[2]</a> Lexical Conversion Library Proposal for TR2 </p> <blockquote> <p> <a class="ext-link" href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1973.html"><span class="icon">​</span>http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1973.html</a> </p> </blockquote> <p> Both have this text: For more involved conversions, such as where precision or formatting need tighter control than is offered by the default behavior of lexical_cast, the conventional stringstream approach is recommended. </p> Ticket René Rivera Tue, 19 Feb 2008 00:35:38 GMT <link>https://svn.boost.org/trac10/ticket/1638#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1638#comment:3</guid> <description> <p> I've run into this problem many, many times. And hadn't realized it was possible to provide for better number conversion. In my opinion allowing such number base conversion is not only within the scope, but by not allowing the conversions it specifically imposes an artificial "tighter control" than the expected behavior. </p> <p> Any chance we can change your mind about this? </p> </description> <category>Ticket</category> </item> </channel> </rss>