#include #include using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char** argv) { //練習1.C++ 標準庫沒有提供所謂的日期類型。 C++ 繼承了C 語言用於日期和時間操作的結構和函數。 //為了使用日期和時間相關的函數和結構,需要在C++ 程序中引用 頭文件。 //有四個與時間相關的類型:clock_t、time_t、size_t 和tm。 //練習1.顯示目前日期時間 //(2)struct tm * localtime (const time_t * timer) //使用 timer 指標的值,來填滿一個 tm 結構中的所有值,它呈現出一個對應的區域時區的時間。 time_t t1 = time(NULL); struct tm * st1 = localtime(&t1); cout<<"目前日期時間 = "<<(st1->tm_year+1900)<<"年"<<(st1->tm_mon+1)<<"月"<tm_mday<<"日"<tm_mday += 10; cout<<"\n10天後日期時間 = "<<(st1->tm_year+1900)<<"年"<<(st1->tm_mon+1)<<"月"<tm_mday<<"日"<