use*_*775 3 c++ time input cin
我在看这段代码时想知道:
#include<iostream>
#include<conio.h>
using namespace std;
int main(){
int a,b;
cout << "enter 1";
cin >> a;
cout << "enter 2";
cin >> b;
getch();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
如果我们可以连续得到变量a和b的输入之间的时间差.
使用time()来获得当前的时间和difftime()计算的差异.
#include <iostream>
#include <ctime>
#include <conio.h>
using namespace std;
int main()
{
int a,b;
cout<<"enter 1";
cin>>a;
time_t atime = time(NULL);
cout<<"enter 2";
cin>>b;
time_t btime = time(NULL);
cout << difftime(btime, atime) << " seconds passed\n";
getch();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
313 次 |
| 最近记录: |