6 延时程序
函数clock()—返回程序开始执行后所用的系统事件
符号常量CLOCKS_PER_SEC:等于每秒钟包含的系统事件单位数
代码:
/*
Project name : _14process_time
Last modified Date: 2022年3月20日20点33分
Last Version: V1.0
Descriptions: 延时程序
*/
# include<iostream>
# include<ctime>
int main()
{
/*
延时程序:
函数clock()---返回程序开始执行后所用的系统事件
符号常量CLOCKS_PER_SEC:等于每秒钟包含的系统事件单位数
*/
using namespace std;
cout << "Enter the delay time,in seconds:";
float secs;
cin >> secs;
clock_t delay = secs * CLOCKS_PER_SEC;
cout << "starting\a\n";
clock_t start = clock();
while (clock() - start < delay);
cout << "done\a\n";
return 0;
}
运行结果:
Enter the delay time,in seconds:2
starting
done
D:\Prj\_C++Self\_14process_time\Debug\_14process_time.exe (进程 9916)已退出,代码为 0。
要在调试停止时自动关闭控制台,请启用“工具”->“选项”->“调试”->“调试停止时自动关闭控制台”。
按任意键关闭此窗口. . .
README
此为本人读C++ Primer总结的笔记,如有错误或知识缺口,请在评论区告知。如本文有在实践中帮到您,是本人的荣幸。