C++ Keeping track of how many seconds has passed since start of program

前端 未结 5 1265
渐次进展
渐次进展 2021-02-05 15:47

I am writing a program that will be used on a Solaris machine. I need a way of keeping track of how many seconds has passed since the start of the program. I\'m talking very sim

5条回答
  •  悲哀的现实
    2021-02-05 15:52

    A very simple method:

    #include 
    time_t start = time(0);
    
    double seconds_since_start = difftime( time(0), start);
    

    The main drawback to this is that you have to poll for the updates. You'll need platform support or some other lib/framework to do this on an event basis.

提交回复
热议问题