Rio*_*iot 1 c++ boost boost-units
如果我只想将一个值从一个单位转换为另一个单位,那么最简单(理想情况是一行)的方法是什么?
例如,我想以米为单位存储一个值,但以英里为单位指定.
大多数执行此操作的示例似乎是多行,涉及typedef和单位定义,并且不提供简单的无单位输出.
嗯 - 我使用以下内容.
#include <boost/units/quantity.hpp>
#include <boost/units/systems/si/length.hpp>
#include <boost/units/base_units/imperial/mile.hpp>
using namespace boost::units;
quantity<si::length> distance_in_metres = static_cast<quantity<si::length> >(
100.0 * boost::units::imperial::mile_base_unit::unit_type()
);
Run Code Online (Sandbox Code Playgroud)
仅供参考 - 我在CPPcon 2015上做了关于Boost装置的教程演示 - 您可以在https://www.youtube.com/watch?v=qphj8ZuZlPA找到它.
| 归档时间: |
|
| 查看次数: |
2647 次 |
| 最近记录: |