How do you print a C++11 time_point?

后端 未结 7 1319
执笔经年
执笔经年 2020-12-07 19:47

I\'ve created a time point, but I have been struggling to print it to the terminal.

#include 
#include 

int main(){

    //set         


        
相关标签:
7条回答
  • 2020-12-07 20:52

    The ctime() does not work for Visual C++. I use MS Visual Studio 2013. I changed the above code to use ctime_s(...), as prompted by MSVC compiler. It worked.

    //set time_point to current time
    std::chrono::time_point<std::chrono::system_clock> time_point;
    time_point = std::chrono::system_clock::now();
    
    std::time_t ttp = std::chrono::system_clock::to_time_t(time_point);
    char chr[50];
    errno_t e = ctime_s(chr, 50, &ttp);
    if (e) std::cout << "Error." << std::endl;
    else std::cout << chr << std::endl;
    
    0 讨论(0)
提交回复
热议问题