我的程序所做的是它首先打印当前时间,然后用户按下回车键。之后它再次打印出时间并计算用户等待按Enter键的时间。
我没时间去减法。我从stackoverflow中的另一个问题获得了打印当地时间的代码。
#include <iostream>
#include <ctime>
using namespace std;
void main()
{
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
printf ( "Current local time and date: %s", asctime (timeinfo) );
cout << "Press enter" << endl;
cin.ignore();
time_t rawtime2;
struct tm * timeinfo2;
time ( &rawtime2 );
timeinfo2 = localtime ( &rawtime2 );
printf ( "Later local time and date: %s", asctime (timeinfo2) );
printf ( "You took %s", ( asctime (timeinfo2) - asctime (timeinfo) ) ); //math won't work here
printf ( " seconds to press enter. ");
cout << endl;
}