首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::literals::chrono_literals::operator""s

Defined in header <chrono>

?

?

constexpr chrono::seconds operator "" s(unsigned long long secs);

(1)

(since C++14)

constexpr chrono::duration</*unspecified*/> operator "" s(long double secs);

(2)

(since C++14)

形成std::chrono::duration文字代表秒。

1%29整数字面值,准确返回std::chrono::seconds(secs)

2%29浮点文字,返回相等于std::chrono::seconds

参数

secs

-

the number of seconds

返回值

std::chrono::duration字面上的。

可能的实施

参数::秒操作符“s%28 unsited长s%29{返回std::秒%28s%29;}conexpr std::crono::工期<long double>运算符“s%28 long Double s%29{返回std::chrono::工期<long double>%28S%29;}

*。

注记

这些运算符在命名空间中声明。std::literals::chrono_literals,两者都是literalschrono_literals是内联命名空间。可以通过以下方式访问这些操作员using namespace std::literals,,,using namespace std::chrono_literals,和using namespace std::literals::chrono_literals...

此外,在命名空间中std::chrono,指令using namespace literals::chrono_literals;由标准库提供,因此如果程序员使用using namespace std::chrono;要获得对工期类的访问权限,工期文字运算符也会变得可见。

std::string还定义operator""s,以表示类型的文字对象。std::string,但是它是一个字符串文本:10s是十秒钟,但是"10"s是两个字符的字符串。

二次

代码语言:javascript
复制
#include <iostream>
#include <chrono>
 
int main()
{
    using namespace std::chrono_literals;
    auto halfmin = 30s;
    std::cout << "half a minute is " << halfmin.count() << " seconds\n"
              << "a minute and a half is " << (1min + 30s).count() << " seconds\n";
}

二次

产出:

二次

代码语言:javascript
复制
half a minute is 30 seconds
a minute and a half is 90 seconds

二次

另见

(constructor)

constructs new duration (public member function of std::chrono::duration)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com