Search
 
SCRIPT & CODE EXAMPLE
 

CPP

C++ sleep for seconds

#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

how to use sleep function in c++ windows

// to use sleep function on windows with c++
#include <Windows.h>
Sleep(3000) // based on milliseconds
Comment

c++ sleep

#include <unistd.h>
// ...
sleep(1); // 1s
Comment

c++ sleep

#include <chrono>
#include <thread>

//sleeping for 3 milliseconds
sleep(3000)
Comment

sleep c++

#include <unistd.h>
unsigned int sleep(unsigned int seconds);
Comment

c++ sleep

std::this_thread::sleep_for(std::chrono::milliseconds(x));
Comment

sleep in c++

#if __WIN32
#include <Windows.h>
#else
#include <unistd.h>
#endif
Comment

ex: c++ sleep function

#include <iostream> 
#include <windows.h> // WinApi header 

using namespace std;

int main() 
{ 
    Beep(523,500); // 523 hertz (C5) for 500 milliseconds     
    cin.get(); // wait 
    return 0; 
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ compile to msi 
Cpp :: nlohmann json, writing to json file 
Cpp :: convert ros time to double 
Cpp :: In every C++ program: 
Cpp :: intage1 was not declared in this scope C++ 
Cpp :: operator = overloading c++ 
Cpp :: opengl triangle example 
Cpp :: c++ find string in string 
Cpp :: subsequence 
Cpp :: Determine if map contains a value for a key c++ 
Cpp :: how a function gives a pointer as parameter c++ 
Cpp :: add for input output file in c/c++ 
Cpp :: Fibonacci Series Program. in c++ 
Cpp :: aliasing c++ 
Cpp :: c++ function with parameters 
Cpp :: no match for ‘operator=’ (operand types are ‘std::basic_ostream’ and ‘int’) 
C :: run time in c 
C :: myFgets in c 
C :: c string is int 
C :: convert string to float c 
C :: c print size_t 
C :: If statement that tests if a value is in range 
C :: operators priority in c 
C :: merge sort code c 
C :: c/c++ type format 
C :: mariadb utf8mb4 
C :: read string with space c 
C :: implicit declaration of function ‘usleep’ [-Wimplicit-function-declaration] 
C :: format specifiers in c 
C :: char to int in c 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =