1//On windows.
2#include<windows.h>
3Sleep(milliseconds);
4
5//On linux.
6#include<unistd.h>
7unsigned int microsecond = 1000000;
8usleep(3 * microsecond);//sleeps for 3 second
9
10// c++ 11 for high resulution.
11
12#include <chrono>
13#include <thread>
14
15int main() {
16 using namespace std::this_thread; // sleep_for, sleep_until
17 using namespace std::chrono; // nanoseconds, system_clock, seconds
18
19 sleep_for(nanoseconds(10));
20 // or
21 sleep_until(system_clock::now() + seconds(1));
22}
23
24// C++ 14 for high resuluton.
25
26#include <chrono>
27#include <thread>
28
29int main() {
30 using namespace std::this_thread; // sleep_for, sleep_until
31 using namespace std::chrono_literals; // ns, us, ms, s, h, etc.
32 using std::chrono::system_clock;
33
34 sleep_for(10ns);
35 // or
36 sleep_until(system_clock::now() + 1s);
37}