How do you add a timed delay to a C++ program?(如何在 C++ 程序中添加定时延迟?)
问题描述
我正在尝试在 C++ 程序中添加定时延迟,想知道是否有人对我可以尝试的内容或可以查看的信息有任何建议?
I am trying to add a timed delay in a C++ program, and was wondering if anyone has any suggestions on what I can try or information I can look at?
我希望我有更多关于我如何实现这个定时延迟的详细信息,但在我有更多关于如何添加一个定时延迟的信息之前,我不确定我应该如何尝试实现这个.
I wish I had more details on how I am implementing this timed delay, but until I have more information on how to add a timed delay I am not sure on how I should even attempt to implement this.
推荐答案
在 Win32 中:
#include<windows.h>
Sleep(milliseconds);
在 Unix 中:
#include<unistd.h>
unsigned int microsecond = 1000000;
usleep(3 * microsecond);//sleeps for 3 second
sleep() 只需要几秒钟,这通常太长了.
sleep() only takes a number of seconds which is often too long.
这篇关于如何在 C++ 程序中添加定时延迟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 C++ 程序中添加定时延迟?
基础教程推荐
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- 提升 ASIO 流缓冲 2021-01-01
- c++ STL设置差异 2022-01-01
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
