c语言的 sleep函数到底在哪个头文件里啊

作者&投稿:稻典 (若有异议请与网页底部的电邮联系)
c语言中sleep()在哪个库中?~

在VC中使用时,sleep函数的头文件为 windows.h,在Linux下,gcc编译器中,使用的头文 件因gcc版本的不同而不同
在VC中,Sleep中的第一个英文字符为大写的"S" ,在linux下不要大写,在标准C中是sleep, 不要大写,简单的说VC用Sleep, 别的一律使用sleep
在VC中,Sleep()里面的单位,是以毫秒为单位,所以如果想让函数滞留1秒的话,应该是Sleep(1000); 在Linux下,sleep()里面的单位是秒,而不是毫秒。
Sleep函数:
功 能: 执行挂起一段时间  
用 法: unsigned sleep(unsigned seconds);  

Sleep方法是Java线程(Thread)开发中一种概念。是线程TIMED_WAITING状态中的一种方法。使用方法为:
1、类名为创建线程的类名。

2、Thread线程Sleep方法的示例代码如下图所示。让main方法运行过程中休眠5000毫秒。

3、Thread线程Sleep方法的示例代码执行结果如下图所示。

4、millis参数含义:以毫秒为单位的睡眠时间长度。nanos参数含义:0-999999额外的纳秒睡眠 。

注意事项:
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



c语言的 sleep函数在<windows.h>头文件里面。

WINDOWS.H是一个最重要的头文件,它包含了其他Windows头文件,这些头文件的某些也包含了其他头文件。这些头文件中最重要的和最基本的是:
1、WINDEF.H 基本数据类型定义。
2、WINNT.H 支持Unicode的类型定义。
3、WINBASE.H Kernel(内核)函数。
4、WINUSER.H 用户界面函数。
5、WINGDI.H 图形设备接口函数。

很确切地告诉楼主,在<windows.h>里面,应该是楼主用的TC2.0里面没有这个头文件,把VC6.0或VS里面的windows.h复制到TC的include 目录下面即可

Sleep

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.

win32程序,dos下程序是不能用<windows.h>头文件