【问题标题】:Whats the alternative to the getdate() function in C++4.3.2? [duplicate]C++4.3.2 中 getdate() 函数的替代方法是什么? [复制]
【发布时间】:2017-03-09 18:29:11
【问题描述】:

这在 Turbo C++ 中运行,但不适用于较新版本的 C++。有什么替代品吗?

#include<stdio.h>
#include<dos.h>

main()
{
   struct date d;
   getdate(&d);
   printf("Current system date is %d/%d/%d\n",d.da_day,d.da_mon,d.da_year);
   return 0;
}

【问题讨论】:

  • int main() 也许?
  • std::chrono 命名空间具有一整套日期和时间函数。
  • 停止使用 Turbo C++,期间。
  • 请,请,选择一个没有过时 20 年的编译器。使用古老的工具学习将成为您的严重障碍。
  • @BoBTFish,NickyC:OP 已经在尝试使用更新的编译器。

标签: c++ turbo-c++


【解决方案1】:

getdate最直接的类比是time + localtime

#include <stdio.h>
#include <time.h>       /* time_t, struct tm, time, localtime */

int main ()
{
    time_t rawtime;
    time ( &rawtime );

    tm * const ptm = localtime ( &rawtime );

    printf("Current system date is %d/%d/%d\n",
             ptm->tm_day,ptm->_mon+1,ptm->tm_year+1900);

    return 0;
}

或者,对于更“C++”风格的方法,查找std::chrono

【讨论】:

    猜你喜欢
    • 2015-07-22
    • 2015-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-07
    • 2011-01-15
    • 2012-01-27
    相关资源
    最近更新 更多