C++函數庫調用實現計時器

#include <iostream>
#include<ctime>

using namespace std;

int main()
{
    cout << "Hello world!" << endl;
    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;
}
發佈了19 篇原創文章 · 獲贊 1 · 訪問量 6995
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章