Boost C++ Libraries: Ticket #7532: lexical_cast fails on complex number with spaces https://svn.boost.org/trac10/ticket/7532 <p> Here's the test code that shows the problem: </p> <pre class="wiki">#include &lt;boost/lexical_cast.hpp&gt; #include &lt;iostream&gt; #include &lt;sstream&gt; #include &lt;string&gt; typedef std::complex&lt;double&gt; Complex; int main() { std::string goodComplex("(1,2)"), badComplex("(1, 2)"); try { Complex foo = boost::lexical_cast&lt;Complex&gt;(goodComplex); std::cout &lt;&lt; "goodComplex = " &lt;&lt; foo &lt;&lt; "\n"; } catch (boost::bad_lexical_cast const &amp; e) { std::cerr &lt;&lt; "goodComplex failed: " &lt;&lt; e.what() &lt;&lt; "\n"; } try { Complex foo = boost::lexical_cast&lt;Complex&gt;(badComplex); std::cout &lt;&lt; "badComplex = " &lt;&lt; foo &lt;&lt; "\n"; } catch (boost::bad_lexical_cast const &amp; e) { std::cerr &lt;&lt; "badComplex failed: "&lt;&lt; e.what() &lt;&lt; "\n"; } { /* Using a stringstream works, though. */ Complex foo; std::istringstream tmpStream(badComplex); tmpStream &gt;&gt; foo; std::cout &lt;&lt; "badComplex printed with stringstream = " &lt;&lt; foo &lt;&lt; "\n"; } } </pre><p> On my machine, with g++ 4.1.2, I get the following result: </p> <pre class="wiki">goodComplex = (1,2) badComplex failed: bad lexical cast: source type value could not be interpreted as target badComplex printed with stringstream = (1,2) </pre><p> For some reason, lexical_cast chokes on the space after the comma, but the stringstream has no problem. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7532 Trac 1.4.3 J. J. Ramsey <jjramsey@…> Fri, 19 Oct 2012 00:26:20 GMT <link>https://svn.boost.org/trac10/ticket/7532#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7532#comment:1</guid> <description> <p> I verified that the bug is still present using the latest stable Boost, 1.51.0, and a newer compiler, g++4.5.4. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Antony Polukhin</dc:creator> <pubDate>Sat, 01 Dec 2012 18:43:46 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/7532#comment:2 https://svn.boost.org/trac10/ticket/7532#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">wontfix</span> </li> </ul> <p> lexical_cast resets the <code>ios_base::skipws</code> flag of an underlying stream object. This behaviour is what usually users want to have. It's unsafe to change it, because it would break some existing users code. </p> Ticket