C++: how to get the actual time with time and localtime?

后端 未结 4 753
暖寄归人
暖寄归人 2021-02-19 03:41

I\'m looking for a way to save the time in a HH::MM::SS fashion in C++. I saw here that they are many solutions and after a little research I opted for time and

4条回答
  •  悲&欢浪女
    2021-02-19 03:59

    You can run continuous clock using following code. It works nicely.

    #include 
    #include  
    #include 
    using namespace std;
    
    void main() {
      while(true) {
        system("cls"); //to clear screen
        time_t tim;
        time(&tim); 
        cout << ctime(&tim); 
        Sleep(1);
      }
    }
    

提交回复
热议问题