// ex5-14.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include <ctime> //describes clock()function,clock_t type
int _tmain(int argc, _TCHAR* argv[])
{
using namespace std;
cout<<"Enter the delay time,in second:";
float secs;
cin>>secs;
clock_t delay = secs*CLOCKS_PER_SEC;//convert to clock ticks
cout<<"starting\a\n";
clock_t start=clock();//返回程序开始执行后到这一步所用的系统时间
while(clock()-start<delay)//检测当前系统时间和开始运行延迟函数的系统时间的差是否小于设定的延迟时间
;
cout<<"done\a\n";
system("pause");
return 0;
}
利用ctime中的clock()编写延时循环
最新推荐文章于 2022-10-30 23:08:11 发布