c++ 中的sleep 函数
来源:互联网 发布:陆小凤系列电影知乎 编辑:程序博客网 时间:2024/06/03 12:29
标准库中无该函数
但在某些编译系统中有,在有些系统库中有,要根据你那边的环境而定。如:
linux中有,unsigned int sleep(unsigned int seconds),传入挂起时间,成功返回0,不成功则返回余下的秒数。windows系统中有Sleep函数(注意大写),void Sleep(DWORD dwMilliseconds); 提供挂起的毫秒数。
例如:
#include<iostream>#include<windows.h>using namespace std;int main(){Sleep(3000);//暂停3秒
S要大写return 0;} Use
std::this_thread::sleep_for
:std::chrono::milliseconds timespan(111605); // or whateverstd::this_thread::sleep_for(timespan);
There is also the complimentary
std::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 a
sleep
function for Windows or Unix:
#ifdef _WIN32 #include <windows.h> void sleep(unsigned milliseconds) { Sleep(milliseconds); }#else #include <unistd.h> void sleep(unsigned milliseconds) { usleep(milliseconds * 1000); // takes microseconds }#endif
But a much simpler pre-C++11 method is to use boost::this_thread::sleep
.
- C语言中的Sleep函数
- C语言中的Sleep函数
- C语言中的Sleep函数
- C语言中的Sleep函数用法
- 关于C语言中的Sleep函数
- javascript中的sleep函数
- php中的sleep()函数
- VC中的Sleep函数
- c++ 中的sleep 函数
- c++ 中的Sleep函数
- Linux中的sleep函数
- perl中的sleep函数
- C++中的Sleep() 函数
- Linux C sleep函数
- c语言:sleep函数
- C语言中的一些时间函数(time/sleep/clock)
- 关于perl中的sleep函数
- Ring0中的Sleep延时函数
- 创新工场2013.9.16笔试、9.17一面、9.18双选会
- linux内核启动
- 枚举类型
- [C#] Winform里调用系统里默认的邮件客户端
- 【D3.js数据可视化系列教程】--(十三)坐标轴
- c++ 中的sleep 函数
- Usage of hash in Perl
- Android中使用Google的GSON框架解析JSON数据----方便快捷(含代码)
- redmine介绍
- 更新Silverlight 后 无法启动调试 未安装Silverlight developer 运行时解决办法
- 安卓自动化测试工具MonkeyRunner之使用ID进行参数化,以及List选择某项和弹出框点击确定的写法
- Android 中设置ListView选中项的背景颜色
- paip.最新的c++ qt5.1.1环境搭建跟hello world
- delphi Stack