Search
 
SCRIPT & CODE EXAMPLE
 

CPP

UNIX c++ delay

#include <iostream>
#include <unistd.h>     //required for usleep()
using namespace std;
int main(){
    //usleep will pause the program in micro-seconds (1000000 micro-seconds is 1 second)
    const int microToSeconds = 1000000;   
    const double delay1 = 2 * microToSeconds;     //2 seconds
    const double delay2 = 4.5 * microToSeconds;     //4.5 seconds
    
    cout<<"Delay 1 in progress... ("<<delay1/microToSeconds<<"s)"<<endl;
    usleep(delay1);        
    cout<<"  => Delay 1 is over"<<endl<<endl;
    
    cout<<"Delay 2 in progress... ("<<delay2/microToSeconds<<"s)"<<endl;
    usleep(delay2);
    cout<<"  => Delay 2 is over"<<endl<<endl;

    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ pause program 
Cpp :: set platformio to C++17 
Cpp :: c++ chrono get milliseconds 
Cpp :: c++ example 
Cpp :: leap year c++ 
Cpp :: stoi c++ 
Cpp :: hello world in cpp 
Cpp :: struct and pointers (retun function) in c++ 
Cpp :: compute the average of an array c++ 
Cpp :: cpp how to input a variable without hitting enter 
Cpp :: angle to vector2 godot 
Cpp :: C++ Kelvin to Celsius 
Cpp :: c++ fast 
Cpp :: stock a file in a vector cpp 
Cpp :: C++ sqlite open file in other directory 
Cpp :: xmake run with arg 
Cpp :: google test assert eq float 
Cpp :: regex for phone number c++ 
Cpp :: max element in vector c++ 
Cpp :: c++ Modulo 10^9+7 (1000000007) 
Cpp :: check if c++ is installed 
Cpp :: how to display a variable in c++ 
Cpp :: cout was not declared in this scope 
Cpp :: cpp goiver all the map values 
Cpp :: convert string into integer in c++ 
Cpp :: convert int to string c++ 
Cpp :: typedef vector c++ 
Cpp :: arduino buildin let 
Cpp :: c++ find element in vector 
Cpp :: c++ struct with default values 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =