Opened 10 years ago
#7261 new Bugs
Boost.Units quantity output overflows ostream width field
Reported by: | Paul A. Bristow | Owned by: | Steven Watanabe |
---|---|---|---|
Milestone: | To Be Determined | Component: | units |
Version: | Boost 1.52.0 | Severity: | Problem |
Keywords: | units ostream width overflow | Cc: | boost@… |
Description
Boost.Units quantity output overflows ostream width field
quantity<length> ql = 2345.6 * meters;
std::cout << std::setw(20) << ql << std::endl;
outputs 22 chars instead of 20 chars.
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.
if os.width() > 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).
(else if os.width() <= 0 then output directly to ostream os as at present).
A test and a patch to deal with this is attached.
(This is not necessarily the most efficient way to deal with this but appears to work).
Attachments (3)
Change History (3)
by , 10 years ago
Attachment: | io.hpp.diff added |
---|
by , 10 years ago
Attachment: | units_measure_width_test.cpp added |
---|
Test file for changes to IO.hpp to correct width overflow
by , 10 years ago
Attachment: | measurement.hpp.diff added |
---|
Diff for changes to /example/measurement.hpp to honor width
Unified diff for units/boost/io.hpp