【C/C++】精确系统延时

在头文件ctime中,定义了一个符号常量CLOCKS_PER_SEC。该常量等于每秒钟包括的系统时间单位数。因此,将系统除以这个单位数,就可以得到秒数。ctime中将clock_t作为clock()作为clock()返回类型的别名。下面具体举例说明:

#include
#include

using namespace std;

void main()
{
	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

该程序是等待n秒,n为你输入的数值。开始和结束都会有铃声.

你可能感兴趣的:(C/C++,算法)