“头文件ctime定义了一个符号常量——CLOCKS_PER_SEC,该常量等于每秒钟包含的系统时间单位数。”
“ctime将clock_t作为clock()返回类型的别名,这意味着可以将变量声明为clock_t类型,编译器将把它转换为long、unsigned int或适合系统的其他类型。”
程序清单5.14 waiting.cpp
#include <iostream>
#include <ctime>
int main()
{
using namespace std;
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;
}
类型别名
“C++为类型建立别名的方式有两种。一种是使用预处理器:”
#define aliasName typeName
“第二种方法是使用C++(和C)的关键字typedef来创建别名:”
typedef typeName aliasName;