Time Limit on C++

Hi All,

I want to end my c++ after, say 360 seconds, and get the output so far. Is there any way to do it?

Thanks

Use <ctime>:
http://www.cplusplus.com/reference/ctime/clock/

The format for setting up a timer is shown in the example on the page

Alternatively, you can look into the std::chrono library for other c++11 options
http://www.cplusplus.com/reference/chrono/
So, will something like this work?:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include<time.h>

int main()
{

    double t = clock();
    while(t < 360)

   {
 
   //my code including for loop

    }
}


If you want the program to only execute for 360 clock ticks then that program should work, but I think you want it to run for 360 seconds?

So:
1
2
while (t / CLOCKS_PER_SEC < 360)
{ ... }

http://www.cplusplus.com/reference/ctime/CLOCKS_PER_SEC/
Topic archived. No new replies allowed.