Boost logo

Boost Users :

Subject: [Boost-users] Units: Are scales for bytes really working?
From: Akim Demaille (akim_at_[hidden])
Date: 2016-12-21 04:53:55


Hi,

I’m trying to run the example given in
http://www.boost.org/doc/libs/1_62_0/doc/html/boost_units/Examples.html#boost_units.Examples.autoscale, and the result is puzzling.

$ cat foo2.cc
#include <iostream>
#include <boost/units/systems/information/byte.hpp>
#include <boost/units/io.hpp>

using namespace std;
using boost::units::binary_prefix;
using boost::units::engineering_prefix;
using boost::units::no_prefix;
using boost::units::symbol_format;
using boost::units::quantity;
using boost::units::information::byte_base_unit;

int main()
{
  cout << BOOST_VERSION << endl;
  // Don't forget that the units name or symbol format specification is persistent.
  cout << symbol_format; // Resets the format to the default symbol format.
  quantity<byte_base_unit::unit_type> b = 2048. * byte_base_unit::unit_type();
  cout << b << endl;
  cout << engineering_prefix << b << endl; // 2.048 kb
  cout << symbol_format << binary_prefix << b << endl; // "2 Kib"
}
$ g++-6 foo2.cc -o foo2
$ ./foo2
106200
2048 B
16.384 kb
16 Kib

What am I doing wrong?

Note that there are a couple of issues in the example as given:

- there should not be any endl after cout << symbol_format;
- using ‘\n’ instead of endl, too many people seem to believe that
  std::endl is the normal way to end the lines
- it would be nice to provide all the needed includes


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net