How to stop execution for a specific time ?

How can I stop the execution flow at a specific point for some time (I need a few seconds) ? I need this for an interactive story telling game, running at console.

Thanks for help.
You can use sleep_for.

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <chrono>
#include <thread>
 
int main()
{
	auto sleepDuration = std::chrono::seconds(2);
	std::cout << "Once upon a time, there was a boy." << std::endl;
	std::this_thread::sleep_for(sleepDuration);
	std::cout << "He was cool." << std::endl;
	std::this_thread::sleep_for(sleepDuration);
	std::cout << "The end." << std::endl;
}


http://en.cppreference.com/w/cpp/thread/sleep_for
Last edited on
Thank you, Peter.
Topic archived. No new replies allowed.