0
How to let a program wait for a certain time in c++?
5 Réponses
+ 3
The standard library implements sleep_for() for this purpose. See the link below for functionality and an example:
https://en.cppreference.com/w/cpp/thread/sleep_for
Similar Threads:
https://www.sololearn.com/discuss/1230117/?ref=app
https://www.sololearn.com/discuss/829815/?ref=app
+ 3
No, the function expects a duration object, which is defined in the <chrono> header and represents time intervals:
https://en.cppreference.com/w/cpp/chrono/duration
This might be a bit confusing, so the standard library defines some operator literals that automatically create an appropriate interval from either an unsigned integer or a double:
1ns => 1 nanosecond
1us => 1 microsecond
1ms => 1 millisecond
1s => 1 second
1min => 1 minute
1h => 1 hour
You can pass these literals any unsigned integer or double, e.g.
5s => 5 seconds
2.5ms => 2.5 milliseconds
Note you might have to write
using namespace std::literals::chrono_literals;
before being able to use them.
You can also use the helper types listed in the reference linked above to create these objects instead.
+ 1
In sleep_for(x)
Is x in seconds?
ps thanks for the responses
0
Oke, thank you verry much!