添加分钟和秒钟.以小时显示 [英] Add minutes and seconds. Display in hours
本文介绍了添加分钟和秒钟.以小时显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我想添加29分60秒并以小时为单位显示结果.
Let's suppose I'd like to add 29 minutes and 60 seconds and display the result in hours.
这里似乎起作用:
cout <<
static_cast<quantity<hour_base_unit::unit_type>>
(quantity<time>{29.0 * minute_base_unit::unit_type()} + 60.0 * seconds)
<< endl;
控制台上显示以下内容:
The following is displayed on the console:
0.5 h
这是推荐的方法吗?有没有更好或更惯用的方式?
Is this the recommended approach? Is there a better or more idiomatic way?
下面是说明上述示例的整个程序.
The entire program illustrating the above example is below.
#include <iostream>
#include <boost/units/systems/si/io.hpp>
#include <boost/units/systems/si.hpp>
#include <boost/units/base_units/metric/hour.hpp>
#include <boost/units/base_units/metric/minute.hpp>
using namespace std;
using namespace boost::units;
using namespace boost::units::si;
using namespace boost::units::metric;
int main()
{
cout <<
static_cast<quantity<hour_base_unit::unit_type>>
(quantity<time>{29.0 * minute_base_unit::unit_type()} + 60.0 * seconds)
<< endl;
return 0;
}
推荐答案
您可以做
(分钟/60 +秒/3600)
(minutes/60+seconds/3600)
这篇关于添加分钟和秒钟.以小时显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文