How to Use usleep Function in C++ Programs? Last Updated : 27 Nov, 2022 Comments Improve Suggest changes Like Article Like Report Halting the program's execution at the desired time for a specific duration is one of the most used features in a programming language. This is generally done to provide some time for input or multithreading. This article will teach you how to use the usleep function to halt the program execution in C++. usleep Function The usleep function is present in the unistd.h header file is used to suspend the program's execution for a certain period. The function takes in argument the time in microseconds for which the program execution would suspend and returns a status code. The function syntax is as follows: int usleep(useconds_t useconds); Where, useconds => Number of microseconds for which the execution is suspended The function returns the value 0 if the execution was successful (execution successfully suspended) else returns -1. Suspending execution using the usleep function Example: C++ #include <iostream> #include <unistd.h> using namespace std; int main() { // Displaying a Statement cout << "1st Line" << endl; // Halting the execution for 10000000 Microseconds (10 seconds) usleep(10000000); // Displaying the line after waiting for 10 seconds cout << "2nd Line" << endl; return 0; } Output: After 10 seconds Explanation: Firstly a string is displayed on the console. Then the usleep function is called with the argument 10000000. Where 10000000 is the time in microseconds which equates to 10 seconds. Hence, the function suspends program execution for 10 seconds once it is called. After which, another line is displayed (after 10 seconds). * The effect could be verified at the end when the program execution time is displayed by the Dev C++ compiler, which is 10.06 seconds, whereas a trivial program like this (without the usleep function call) would execute in under 1 second. This could be used to verify the functionality of the program. Comment More infoAdvertise with us Next Article How to Use usleep Function in C++ Programs? V vasudev4 Follow Improve Article Tags : Technical Scripter C++ Technical Scripter 2022 CPP-Functions Practice Tags : CPP Similar Reads Sleep Function in C++ C++ provides the functionality of delay or inactive state of the program with the help of the operating system for a specific period of time. Other CPU operations will function adequately but the sleep() function in C++ will sleep the present executable for the specified time by the thread.The sleep 3 min read raise() function in C++ csignal header file declared the function raise() to handle a particular signal. Signal learns some unusual behavior in a program, and calls the signal handler. It is implemented to check if the default handler will get called or it will be ignored. Syntax: int raise ( int signal_ ) Parameter: The f 3 min read strol() function in C++ The strtol() function in C++ interprets the contents of a string as an integral number of the specified base and return its value as a long int.This function also sets an end pointer that points to the first character after the last valid numeric character of the string, if there is no such characte 3 min read Function Pointer in C++ Prerequisites: Pointers in C++Function in C++ Pointers are symbolic representations of addresses. They enable programs to simulate call-by-reference as well as to create and manipulate dynamic data structures. Iterating over elements in arrays or other data structures is one of the main use of point 4 min read wcstol() function in C/C++ The wcstol() function in C/C++ converts the given wide string to a long integer. This function sets a pointer to point to the first character after the last valid character of the wide string if there is any, otherwise, the pointer is set to null. This function ignores all the leading whitespace cha 3 min read unordered_set emplace_hint() function in C++ STL The unordered_set::emplace_hint() function is an inbuilt function in C++ STL which inserts a new element in the unordered_set only if the value to be inserted is unique, with a given hint. Syntax: unordered_set_name.emplace_hint( position, value ) Parameter: This function accepts two parameters as m 2 min read ios manipulators unitbuf() function in C++ The unitbuf() method of stream manipulators in C++ is used to set the unitbuf format flag for the specified str stream. This flag flushes the associated buffer after each operation. Syntax: ios_base& unitbuf (ios_base& str) Parameters: This method accepts str as a parameter which is the stre 2 min read std::function in C++ The std::function() in C++ is a function wrapper class which can store and call any function or a callable object. In this article, we will learn about std::function in C++ and how to use it in different cases.Table of ContentWhat is std::function in C++?Example of std::functionMember Functions of s 5 min read log() Function in C++ The std::log() in C++ is a built-in function that is used to calculate the natural logarithm (base e) of a given number. The number can be of any data type i.e. int, double, float, long long. It is defined inside the <cmath> header file.In this article we will learn about how to use std::log() 1 min read Like