2016-10-27 88 views
-3

這運行在Turbo C++中,但不適用於較新版本的C++。任何替代方案?什麼是C++ 4.3.2中getdate()函數的替代方法?

#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

'INT主要()'可能? – Treycos

+2

'std :: chrono'命名空間有一整套日期和時間函數。 –

+3

停止使用Turbo C++,期限。 –

回答

0

最直接的類比getdatetime + 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

相關問題