gpt4 book ai didi

c++ - 试图计算两次之间的差异,不会减去

转载 作者:太空狗 更新时间:2023-10-29 23:52:25 26 4
gpt4 key购买 nike

我的程序所做的是首先打印当前时间,然后用户按下回车键。之后它再次打印出时间并计算用户等待按下回车键的时间。

我没时间做减法。我从 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;
}

最佳答案

cout << "Elapsed time: " << rawtime2 - rawtime << " seconds" << endl;

关于c++ - 试图计算两次之间的差异,不会减去,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15858552/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com