If I have a
std::chrono::steady_clock::time_point t1 = std::chrono::steady_clock::now();
variable, how can I define another time_point variable t2
such that it represents the time point exactly one second after of t1
?
Something like auto t2 = t1 + "1s"
. What should I replace "1s" with?
If you are using C++14 (VS-2015, or -std=c++14
with gcc or clang), then:
using namespace std::chrono_literals;
auto t2 = t1 + 1s;
If you are using C++11:
using namespace std::chrono;
auto t2 = t1 + seconds{1};
If you don't want to make a copy, but add 1 second to t1
itself, +=
is also ok:
t1 += 1s;
t1 += seconds{1};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With