最近在看c++ primer plus第六版,虽然学了很久的c++了,看这本经典书依然有收获。
碰到一个有意思的程序,记录一下。
#include <iostream> #include <ctime> int main(){ std::cout << "Enter the delay time, in seconds" << std::endl; float seconds; std::cin >> seconds; clock_t delay = seconds*CLOCKS_PER_SEC; std::cout << "starting \n" ; clock_t start = clock(); while (clock()-start<delay){ } std::cout << "done\n"; return 0; }