在我的程序中,我試圖在一天//月//年佈局中顯示今天的日期。我嘗試過使用許多不同的方法,但我不斷收到有關不安全使用cTime的錯誤。顯示今天的日期
有沒有讓我的程序來顯示日期的簡單方法:
time_t t = time(0); // get time now
struct tm * now = localtime(& t);
cout << (now->tm_year + 1900) << '-'
<< (now->tm_mon + 1) << '-'
<< now->tm_mday
<< endl;
我不斷收到「‘本地時間’:此函數或變量可能是不安全的考慮使用localtime_s來代替。」 所以我做到了,現在我得到 「localtime_s」:函數不接受1個參數
如果可用,請使用'std :: put_time'。 – chris
你究竟試過了什麼?哪裏有問題?你會得到什麼錯誤? – Varaquilex
你有沒有看到這個http://stackoverflow.com/questions/997946/how-to-get-current-time-and-date-in-c? – mchfrnc