调用系统函数,可以得到系统时间
1 #include<iostream> 2 #include<windows.h> 3 #include<time.h> 4 using namespace std; 5 int main() 6 { 7 time_t rawtime; 8 9 while(true){ 10 time(&rawtime); 11 tm *timeinfo=localtime(&rawtime); 12 system("cls"); 13 cout<<timeinfo->tm_year+1900<<"年"<<timeinfo->tm_mon+1<<"月"<<timeinfo->tm_mday<<"日"<<endl; 14 cout<<timeinfo->tm_hour<<":"<<timeinfo->tm_min<<":"<<timeinfo->tm_sec<<endl; 15 Sleep(1000); 16 } 17 return 0; 18 }