下面的代码仅限于windows平台,因为windows.h头文件只存在与windows系统中。
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
int main()
{
//获得当前系统的时间
cout << time(NULL) << endl;
//暂停1000毫秒
Sleep(1000);
cout << time(NULL) << endl;
//根据系统时间设置伪随机数种子
srand((unsigned)time(NULL));
//输出随机数
cout << rand() << endl;
return 0;
}