C++里面的随机数函数是?还有它是在哪个头文件里面?
怎么取系统时间?函数是?time(参数如何设?)
先回答你的第二个问题吧,
怎么取系统时间?代码如下,你看了就懂了。
#include <iostream.h>
#include <time.h>
int main()
{
int second = 0; //临时参数,用来与当前时间比较
while(true) //实现了每N秒钟执行一条语句的功能
{
time_t time_now = time(0); //调用系统函数,并初始化
struct tm *time_p = gmtime(&time_now); //获取当前时间
if (time_p->tm_sec != second) //判断时间是否更新
{
if (time_p->tm_sec % 3 == 0) //每三秒钟执行一条语句
{
cout << "The current time is :"
<< time_p->tm_hour
<< ":"
<< time_p->tm_min
<< ":"
<< time_p->tm_sec
<< endl;
cout << "hello, jijian!"
<< endl;
}
}
second = time_p->tm_sec; //更新临时变量
}
return 0;
}