Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,940 questions

51,877 answers

573 users

How to run a loop for 5 seconds

1 Answer

0 votes
#include <iostream>
#include <chrono>
#include <thread>

int main() {

	for (int i = 0; i < 5; i++) {
		std::cout << "second: " << i + 1 << "\n";
		std::this_thread::sleep_for(std::chrono::milliseconds(1000));
	}
}



/*
run:

second: 1
second: 2
second: 3
second: 4
second: 5

*/

 



answered Dec 11, 2024 by avibootz

Related questions

1 answer 85 views
1 answer 105 views
1 answer 97 views
1 answer 105 views
1 answer 96 views
2 answers 138 views
2 answers 136 views
...