为了账号安全,请及时绑定邮箱和手机立即绑定

while (clock() - start < delay ) 这里的clock()

while (clock() - start < delay ) 这里的clock()

C C++
xungeer29 2017-10-06 18:56:57
#include <iostream>#include <ctime> // describes clock() function, clock_t typeint main(){using namespace std;cout << "Enter the delay time, in seconds: ";float secs;cin >> secs;clock_t delay = secs * CLOCKS_PER_SEC;  // convert to clock tickscout << "starting\a\n";clock_t start = clock();                这里和下一句没看懂,什么意思?clock()赋给start 了,怎么再减啊?while (clock() - start < delay )        // wait until time elapses;                                   // note the semicoloncout << "done \a\n";return 0;}
查看完整描述

1 回答

已采纳
?
望远

TA贡献1017条经验 获得超1032个赞

//clock()是C/C++中的计时函数,而与其相关的数据类型是clock_t。在MSDN中,查得对clock函数定义如下:
clock_t clock(void) ;
//这个函数返回从“开启这个程序进程”到“程序中调用clock()函数”时之间的CPU时钟计时单元(clock tick)数,在MSDN中称之为挂钟时间(wal-clock);若挂钟时间不可取,则返回-1。其中clock_t是用来保存时间的数据类型。
clock_t delay = secs * CLOCKS_PER_SEC;//这是将延迟时间秒-->CPU时钟计时单元
while (clock()-start < delay);
//通过这个循环来每次取出新的CPU时钟计时单元,减去一开始的start单元时间,获得时间差,来延时


查看完整回答
1 反对 回复 2017-10-06
  • xungeer29
    xungeer29
    clock_t start = clock();那这句是什么意思?
  • 望远
    望远
    取出一开始的起始cpu时钟计时单元,就是计算延时的起始时间,从这个时候开始计时.
  • xungeer29
    xungeer29
    非常感谢
点击展开后面1
  • 1 回答
  • 0 关注
  • 1947 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信