我正在打印当前时间,但我的数量与时间无关
I am printing the current time but I am getting a large number unrelated to time
我需要计算出一种时间。这是一项家庭作业,我的老师说<ctime>
包括1987年以来的一些功能,可以告诉您从那时起的时间。这是在排序之前和之后运行的,两个值之间的差异是排序时间。但是,我找不到与时间函数有关的任何内容&amp;1987 ...有人知道他在说什么还是有其他方法可以计算排序时间?
int main()
{
int n;
vector<int> data;
time_t t =time(0);
cout<<"Vector length?: "<<endl;
cin>>n;
srand(time(0));
for (int i=0; i<n; i++)
{
data.push_back(rand()%20+1);
}
cout<<"Vector: "<<endl;
for (int i=0; i<n; i++)
{
cout<<data[i]<<" "<<endl;
}
cout<<"Time: "<<t<<endl;
insertionSort(data);
cout<<"***Insertion Sorted Vector*** "<<endl;
//cout<<"Time taken: "<<i_t2-i_t1<<endl;
system("Pause");
return 0;
}
http://www.cplusplus.com/reference/ctime/time/
功能时间
time_t time (time_t* timer);
获得当前时间获取当前日历时间作为类型的值 time_t。
函数返回此值,如果参数不是null 指针,它还将此值设置为计时器指向的对象。
返回的值通常 00:00小时,1970年1月1日UTC(即当前的UNIX时间戳)。 尽管库可能会使用不同的时间表示: 便携式程序不应使用此功能返回的值 直接,但始终依靠对标准其他元素的调用 库将它们翻译成便携式类型(例如Localtime,GMTime 或 difftime )。
/* time example */
#include <stdio.h> /* printf */
#include <time.h> /* time_t, struct tm, difftime, time, mktime */
int main ()
{
time_t timer;
struct tm y2k = {0};
double seconds;
y2k.tm_hour = 0; y2k.tm_min = 0; y2k.tm_sec = 0;
y2k.tm_year = 100; y2k.tm_mon = 0; y2k.tm_mday = 1;
time(&timer); /* get current time; same as: timer = time(NULL) */
seconds = difftime(timer,mktime(&y2k));
// ^^^^^^^ see difftime here
printf ("%.f seconds since January 1, 2000 in the current timezone", seconds);
return 0;
}
相关文章:
- 我的固定时间步长与增量时间和插值的解决方案是错误的吗?
- 为什么在尝试测量函数返回所需的时间时,我的运行时编号是错误的?
- 我不明白为什么我的代码不起作用并且需要更长的时间来运行
- 我的 c++ 应用程序中的运行时间从 0 增加到 60 太快了(例如一毫秒或一微秒)
- 如何将我的每个矢量字符串转换为纪元时间日期
- 如何确保我的 Arduino 秒表的时间准确?
- 随着时间的推移,我的程序越来越慢,我不知道为什么.内存泄漏
- 我的C++程序如何访问计算机的日期和时间以打印和使用当前年份?
- 为什么我的代码在"decrease to zero"问题中被时间超过了
- 我怎样才能阻止我的程序输出时间,它使我的程序难以阅读
- 测量我的随机数数组打印的时间始终显示为 0 秒
- 需要减少我的C++代码的执行时间
- 为什么这个经过的时间(帧时间)计算会锁定我的游戏
- 我的 RSU 如何在静脉中以周期性的时间间隔调用函数
- 无法将 int 类型转换为时间类型(我的类类型)
- 我的开关菜单在一段时间循环中出现问题
- 为什么glm :: mat3和glm :: value_ptr会在时间和宇宙中创建一个黑洞,并且正在破坏我的脑海中
- 为什么我的多线程示例需要与任何一个相同的时间
- 为什么我的 for 循环在 UNIX 环境中执行额外的时间
- 编译我的C++代码需要很长时间