c语言的 sleep函数到底在哪个头文件里啊
在<windows.h>里面。
在VC中使用时,sleep函数的头文件为windows。h,在Linux下,gcc编译器中,使用的头文件因gcc版本的不同而不同
在VC中,Sleep中的第一个英文字符为大写的"S",在linux下不要大写,在标准C中是sleep,不要大写,简单的说VC用Sleep,别的一律使用sleep
在VC中,Sleep()里面的单位,是以毫秒为单位,所以如果想让函数滞留1秒的话,应该是Sleep(1000);在Linux下,sleep()里面的单位是秒,而不是毫秒。
扩展资料:
Windows.h头文件之所重要,是因为头文件封装了许多库函数以及一些类,将一些复杂的工作由库函数处理,Windows.h头文件中包含了Windef.h、Winnt.h、Winbase.h、Winuser.h、Wingdi.h等头文件,涉及到了Windows内核API,图形界面接口,图形设备函数等重要的功能。
在C语言家族程序中,头文件被大量使用。一般而言,每个C++/C程序通常由头文件和定义文件组成。头文件作为一种包含功能函数、数据接口声明的载体文件,主要用于保存程序的声明,而定义文件用于保存程序的实现。
参考资料来源:百度百科-windows.h
WINDOWS.H是一个最重要的头文件,它包含了其他Windows头文件,这些头文件的某些也包含了其他头文件。这些头文件中最重要的和最基本的是:
1、WINDEF.H 基本数据类型定义。
2、WINNT.H 支持Unicode的类型定义。
3、WINBASE.H Kernel(内核)函数。
4、WINUSER.H 用户界面函数。
5、WINGDI.H 图形设备接口函数。
The Sleep function suspends the execution of the current thread for at least the specified interval.
To enter an alertable wait state, use the SleepEx function.
VOID Sleep(
DWORD dwMilliseconds
);
Parameters
dwMilliseconds
[in] Minimum time interval for which execution is to be suspended, in milliseconds.
A value of zero causes the thread to relinquish the remainder of its time slice to any other thread of equal priority that is ready to run. If there are no other threads of equal priority ready to run, the function returns immediately, and the thread continues execution.
A value of INFINITE indicates that the suspension should not time out.
Return Values
This function does not return a value.
Remarks
This function causes a thread to relinquish the remainder of its time slice and become unrunnable for at least the specified number of milliseconds, after which the thread is ready to run. In particular, if you specify zero milliseconds, the thread will relinquish the remainder of its time slice but remain ready. Note that a ready thread is not guaranteed to run immediately. Consequently, the thread may not run until some time after the specified interval elapses. For more information, see Scheduling Priorities.
You have to be careful when using Sleep and code that directly or indirectly creates windows. If a thread creates any windows, it must process messages. Message broadcasts are sent to all windows in the system. If you have a thread that uses Sleep with infinite delay, the system will deadlock. Two examples of code that indirectly creates windows are DDE and COM CoInitialize. Therefore, if you have a thread that creates windows, use MsgWaitForMultipleObjects or MsgWaitForMultipleObjectsEx, rather than Sleep.
Example Code
For an example, see Using Thread Local Storage.
Requirements
Client Requires Windows XP, Windows 2000 Professional, Windows NT Workstation, Windows Me, Windows 98, or Windows 95.
Server Requires Windows Server 2003, Windows 2000 Server, or Windows NT Server.
Header Declared in Winbase.h; include Windows.h.
Library Link to Kernel32.lib.
DLL Requires Kernel32.dll.