📅  最后修改于: 2022-03-11 14:44:54.954000             🧑  作者: Mango
//On windows.
#include
Sleep(milliseconds);
//On linux.
#include
unsigned int microsecond = 1000000;
usleep(3 * microsecond);//sleeps for 3 second
// c++ 11 for high resulution.
#include
#include
int main() {
using namespace std::this_thread; // sleep_for, sleep_until
using namespace std::chrono; // nanoseconds, system_clock, seconds
sleep_for(nanoseconds(10));
// or
sleep_until(system_clock::now() + seconds(1));
}
// C++ 14 for high resuluton.
#include
#include
int main() {
using namespace std::this_thread; // sleep_for, sleep_until
using namespace std::chrono_literals; // ns, us, ms, s, h, etc.
using std::chrono::system_clock;
sleep_for(10ns);
// or
sleep_until(system_clock::now() + 1s);
}