clock() function always returning 0 [duplicate]

不问归期 提交于 2019-12-02 01:49:01

clock() returns the number of ticks USED SINCE THE PROGRAM STARTED executing. There is no need (in this specific) example to get the clock_t begin value.

Try printing out both the begin and end values and see what they are. They're likely both 0 or close to 0 as waiting for user input doesn't use CPU time.

Either way, I recommend the time() function as you don't need tick precision. http://www.cplusplus.com/reference/clibrary/ctime/time/

I think you should be using the time() function. Here is how it works: http://asust.in/007D You just call it and it returns the number of seconds since Unix epoch (January 1, 1970).

The clock() function returns the number of clock ticks since the program started. Here: http://asust.in/007E

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!