什么是C ++ 4.3.2中getdate()函数的替代品?

时间:2016-10-27 07:12:57

标签: c++ turbo-c++

这在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;
}

1 个答案:

答案 0 :(得分:0)

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;
}

或者,对于更多&#34; C ++&#34;样式方法,查找std::chrono