gpt4 book ai didi

C++11:将 time_point 增加一秒

转载 作者:行者123 更新时间:2023-12-04 14:25:21 25 4
gpt4 key购买 nike

如果我有一个

std::chrono::steady_clock::time_point t1 = std::chrono::steady_clock::now();

变量,我如何定义另一个 time_point 变量 t2使得它准确地代表时间点 一秒 之后 t1 ?

类似 auto t2 = t1 + "1s" .我应该用什么代替“1s”?

最佳答案

如果您使用 C++14(VS-2015,或 -std=c++14 和 gcc 或 clang),则:

using namespace std::chrono_literals;
auto t2 = t1 + 1s;

如果您使用的是 C++11:
using namespace std::chrono;
auto t2 = t1 + seconds{1};

如果您不想复制,但在 t1 上加 1 秒本身, +=也可以:
t1 += 1s;
t1 += seconds{1};

关于C++11:将 time_point 增加一秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36761128/

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