![]() |
In C++, there is the functionality of delay or inactive state which allows the execution to be delayed for a specific period of time. This is often referred to as a “timed delay”. In this article, we will learn how to add timed delay in C++. Timed Delay in C++To add a timed delay in C++, we can use the std::this_thread::sleep_for() function from the <thread> library. Pass the duration of the delay as a parameter to the sleep_for() function using chrono::seconds(), which will pause the execution of the program for the specified duration. Syntax to Use sleep_for Functionthis_thread::sleep_for(chrono::duration(time_period)); Here,
C++ Program to Add Timed DelayThe below program demonstrates how we can add timed delay in C++.
Starting the countdown...
|
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 14 |