-3

This runs in Turbo C++, but doesn't work on newer versions of C++. Any alternatives to this?

#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;
}
StoryTeller - Unslander Monica
  • 159,632
  • 21
  • 358
  • 434
Yashit
  • 71
  • 2
  • 7

1 Answers1

0

The most direct analogy to getdate is 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;
}

Alternatively, for a more "C++" style approach, look up std::chrono