Boost C++ Libraries: Ticket #7261: Boost.Units quantity output overflows ostream width field https://svn.boost.org/trac10/ticket/7261 <p> Boost.Units quantity output overflows ostream width field </p> <blockquote> <p> quantity&lt;length&gt; ql = 2345.6 * meters; </p> </blockquote> <blockquote> <p> std::cout &lt;&lt; std::setw(20) &lt;&lt; ql &lt;&lt; std::endl; </p> </blockquote> <p> outputs 22 chars instead of 20 chars. </p> <p> The reason is that the first item value() is output using the ios width setting, but the second unit() 'm' (and separating space) is not. </p> <p> if os.width() &gt; 0 then a way is to build a single string of the quantity with the width specified for example using an ostringstream (otherwise, outputing value and unit (perhaps autoprefixed to km) severally would overflow the width). </p> <p> (else if os.width() &lt;= 0 then output directly to ostream os as at present). </p> <p> A test and a patch to deal with this is attached. </p> <p> (This is not necessarily the most efficient way to deal with this but appears to work). </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7261 Trac 1.4.3 Paul A. Bristow Wed, 22 Aug 2012 16:39:58 GMT attachment set https://svn.boost.org/trac10/ticket/7261 https://svn.boost.org/trac10/ticket/7261 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">io.hpp.diff</span> </li> </ul> <p> Unified diff for units/boost/io.hpp </p> Ticket Paul A. Bristow Wed, 22 Aug 2012 16:42:21 GMT attachment set https://svn.boost.org/trac10/ticket/7261 https://svn.boost.org/trac10/ticket/7261 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">units_measure_width_test.cpp</span> </li> </ul> <p> Test file for changes to IO.hpp to correct width overflow </p> Ticket Paul A. Bristow Thu, 23 Aug 2012 13:33:10 GMT attachment set https://svn.boost.org/trac10/ticket/7261 https://svn.boost.org/trac10/ticket/7261 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">measurement.hpp.diff</span> </li> </ul> <p> Diff for changes to /example/measurement.hpp to honor width </p> Ticket