在GCC中,sleep函数的头文件是什么?

Victor_Dinho 2009-07-31 04:18:49
我想尝试一下sleep函数,但编译就是不成功,说
C:\Documents and Settings\clerk\My Documents\test.cpp|11|error: `sleep' was not declared in this scope
我怀疑就是头文件的问题,然后在网上搜了几种:stdio.h、stdlib.h和unistd.h,但结果都一样。
那实际上sleep函数的头文件究竟是什么呢?

我用的是CodeBlock带的GNU GCC Compiler。
...全文
10831 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
guyanqiu 2010-02-01
  • 打赏
  • 举报
回复
#if !defined __NO_ISOCEXT
#include <sys/types.h> /* For useconds_t. */

int __cdecl __MINGW_NOTHROW usleep(useconds_t useconds);
#endif

实验了 usleep()函数,编译正常,程序运行正常,可是,不论延时多少,都是一闪而过。
我没有找到sleep。
xrjkgd 2009-12-30
  • 打赏
  • 举报
回复
强大
WIND_ 2009-10-26
  • 打赏
  • 举报
回复
确切说
windows下:
#include <windows.h>


Linux下:
#include <unistd.h>
WIND_ 2009-10-26
  • 打赏
  • 举报
回复
#include <unistd.h>
guiwen517 2009-08-01
  • 打赏
  • 举报
回复
SYNOPSIS
#include <unistd.h>

unsigned int sleep(unsigned int seconds);


gcc
mymtom 2009-07-31
  • 打赏
  • 举报
回复


#if defined(WIN32) || defined(WIN64)
#include <windows.h>
#define sleep(n) Sleep(1000 * (n))
#else
#include <unistd.h>
#endif

过去的我 2009-07-31
  • 打赏
  • 举报
回复
windows.h
danny 2009-07-31
  • 打赏
  • 举报
回复
我的是在unistd.h中..
stdio.h、stdlib.h这俩里没有的.
gcc 4.3.2

原型是: extern unsigned int sleep(unsigned int __seconds)
以秒为单位的..


...你的是windows环境哦.
Victor_Dinho 2009-07-31
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 lcl_data 的回复:]
C/C++ code函数名: sleep
功 能: 执行挂起一段时间
用 法: unsigned sleep(unsigned seconds);
程序例:

#include<dos.h>
#include<stdio.h>int main(void)
{int i;for (i=1; i<5; i++)
{
printf("Sleeping for %d ¡­
[/Quote]

你的程序我也搜到过,但编译有错误。
十八道胡同 2009-07-31
  • 打赏
  • 举报
回复
函数名: sleep 
功 能: 执行挂起一段时间
用 法: unsigned sleep(unsigned seconds);
程序例:

#include <dos.h>
#include <stdio.h>

int main(void)
{
int i;

for (i=1; i<5; i++)
{
printf("Sleeping for %d seconds\n", i);
sleep(i);
}
return 0;
}
函数名: sleep
功 能: 执行挂起一段时间
用 法: unsigned sleep(unsigned seconds);
程序例:

#include <dos.h>
#include <stdio.h>

int main(void)
{
int i;

for (i=1; i<5; i++)
{
printf("Sleeping for %d seconds\n", i);
sleep(i);
}
return 0;
}
Victor_Dinho 2009-07-31
  • 打赏
  • 举报
回复 1
[Quote=引用 1 楼 supermegaboy 的回复:]
就在stdlib中,叫_sleep()
[/Quote]

现在程序可以运行了,但编译的时候有个warning:

C:\Documents and Settings\clerk\My Documents\test.cpp||In function `int main()':|
C:\Documents and Settings\clerk\My Documents\test.cpp|11|warning: `_sleep' is deprecated (declared at C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/stdlib.h:395)|
C:\Documents and Settings\clerk\My Documents\test.cpp|11|warning: `_sleep' is deprecated (declared at C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/stdlib.h:395)|
||=== Build finished: 0 errors, 2 warnings ===|

不知道能不能去掉~~
飞天御剑流 2009-07-31
  • 打赏
  • 举报
回复 1
就在stdlib中,叫_sleep()

64,683

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧