The 'clock()' function in C++ returns the number of clock ticks elapsed since the program started. Clock ticks are implementation-dependent and may vary from system to system.

To output the result of the 'clock()' function, you can use a 'cout' statement:

#include <iostream>
#include <ctime>

int main() {
    clock_t start = clock();
    
    // Code to measure the time
    
    clock_t end = clock();
    double duration = (double)(end - start) / CLOCKS_PER_SEC;
    
    std::cout << 'Time elapsed: ' << duration << ' seconds' << std::endl;
    
    return 0;
}

This code measures the time it takes for the code between the 'start' and 'end' variables to execute and then outputs the duration in seconds. Note that you need to include the '' header to use the 'clock()' function and the 'CLOCKS_PER_SEC' constant.


原文地址: http://www.cveoy.top/t/topic/o2Kf 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录