c 中的sleep 函式

2021-06-18 09:51:08 字數 1173 閱讀 6599

標準庫中無該函式

但在某些編譯系統中有,在有些系統庫中有,要根據你那邊的環境而定。

如:linux中有,unsigned int sleep(unsigned int seconds),傳入掛起時間,成功返回0,不成功則返回餘下的秒數。

windows系統中有sleep函式(注意大寫),void sleep(dword dwmilliseconds); 提供掛起的毫秒數。

例如:#include#includeusing namespace std;

int main()

usestd::this_thread::sleep_for:

std

::chrono

::milliseconds timespan

(111605

);// or whatever

std::

this_thread

::sleep_for

(timespan

);

there is also the complimentarystd::this_thread::sleep_until.

prior to c++11, c++ had no thread concept and no sleep capability, so your solution was necessarily platform dependent. here's a snippet that defines asleepfunction for windows or unix:

#ifdef

_win32

#include

void

sleep

(unsigned

milliseconds

)#else

#include

void

sleep

(unsigned

milliseconds

)#endif

but a much ******r pre-c++11 method is to use boost::this_thread::sleep.

Linux中的sleep函式

環境 vmware workstation centos 6.4 x86 64 說明 1 linux系統下可以使用sleep函式。2 sleep函式在標頭檔案 include 中。3 sleep函式的定義 unsigned int sleep unsigned int seconds 4 函式的引數...

linux中sleep函式使用

應用程式 include usleep n n微秒 sleep n n毫秒 sleep n n秒 驅動程式 include mdelay n milliseconds 其實現 ifdef notdef define mdelay n else define mdelay n builtin cons...

linux中sleep函式使用

應用程式 include usleep n n微秒 sleep n n毫秒 sleep n n秒 驅動程式 include mdelay n milliseconds 其實現 ifdef notdef define mdelay n else define mdelay n builtin cons...