gpt4 book ai didi

c++ - 如何使用此库将秒数转换为分钟数?

转载 作者:行者123 更新时间:2023-11-30 01:33:38 25 4
gpt4 key购买 nike

我有一个 program使用这个流行的 library ,但是我很难用它来将秒数转换为分钟数

下面的代码...

#include <iostream>

#include "units.h"

int main(int argc, const char * argv[])
{
{
long double one = 1.0;

units::time::second_t seconds;
units::time::minute_t minutes(one);

seconds = minutes;

std::cout << "1 minute is " << seconds << std::endl;
}


{
long double one = 1.0;

units::time::second_t seconds(one);
units::time::minute_t minutes;

minutes = seconds;

std::cout << "1 second is " << minutes << std::endl;
}

return 0;
}

产生...

1 minute is 60 s
1 second is 1 s

然而,我本以为它会产生……

1 minute is 60 s
1 second is .016666667 m

最佳答案

库提供了一个units::convert方法,查看文档here .

这是一个工作片段:

    long double one = 1.0;

units::time::second_t seconds(one);
units::time::minute_t minutes;

minutes = seconds;

std::cout << "1 second is " << minutes << std::endl;
std::cout << "1 second is "
<< units::convert<units::time::seconds, units::time::minutes>(seconds)
<< std::endl;

有关更多信息,我建议在 doc 中搜索.

关于c++ - 如何使用此库将秒数转换为分钟数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58197932/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com