Boost logo

Boost Users :

Subject: Re: [Boost-users] getting started with Boost::Units
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-01-08 18:08:15


AMDG

Mark Volkmann wrote:
> The first thing I'm trying to do is determine how to represent a
> velocity in miles per hour. I haven't been able to figure it out from
> the documentation. Any hints would be appreciated.

// Get the associated base units
#include <boost/units/base_units/us/mile.hpp>
#include <boost/units/base_units/metric/hour.hpp>
// Create short typedefs for the components.
typedef boost::units::us::mile_base_unit::unit_type mile_unit;
typedef boost::units::metric::hour_base_unit::unit_type hour_unit;
// make the unit for miles/hour
typedef boost::units::divide_typeof_helper<mile_unit, hour_unit>::type
miles_per_hour;

quantity<miles_per_hour> mph = 80.0*miles_per_hour();

> I also need to figure out the best way to get string representations
> of quantities that include their units for output.

#include <boost/units/io.hpp>
will give you operator<<.

In Christ,
Steven Watanabe


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