Help me with chrono library!

Hi, i want make a loop that stop when spending 15 seconds in code:

#include <iostream>
#include <chrono>

using namespace std;

int main()
{
int cont;
chrono::system_clock::time_point tempo;
chrono::duration<double> duracao;

tempo = chrono::system_clock::now();

while(tempo != 15){
cont++;
}

duracao = chrono::duration_cast<chrono::duration<double> >(chrono::system_clock::now() - tempo);

cout <<"cont = " << cont << endl;
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <chrono>

int main()
{
	using namespace std::chrono;

	int value = 0;

	auto limit = seconds(2);

	auto begin = system_clock::now();
	auto end = begin;

	while (end = system_clock::now(), end - begin < limit)
		++value;

	std::cout << "Value: " << value << '\n';
}
Topic archived. No new replies allowed.