Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making C++ pause

Is there a C++ equivalent to Python's time.sleep()?

like image 234
rectangletangle Avatar asked Dec 02 '25 08:12

rectangletangle


2 Answers

Use boost::this_thread::sleep

// sleep for 5 seconds
boost::this_thread::sleep(boost::posix_time::seconds(5)); 
like image 77
Benjamin Lindley Avatar answered Dec 03 '25 22:12

Benjamin Lindley


The following code will sleep for 10 milliseconds.

boost::this_thread::sleep(boost::posix_time::milliseconds(10))

Refer to boost::posix_time::time_duration for more ways to construct the duration.

like image 37
jhourback Avatar answered Dec 03 '25 21:12

jhourback



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!