“Schlaf in CPP” Code-Antworten

Schlaf in CPP

#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;
}
ALeonidou

c Schlaf

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

c Schlaf

#include <chrono>
#include <thread>

//sleeping for 3 milliseconds
sleep(3000)
dl.guy

c Schlaf

std::this_thread::sleep_for(std::chrono::milliseconds(x));
Michael Mainbird

Schlaf c

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

Schlaf in c

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

Ähnliche Antworten wie “Schlaf in CPP”

Fragen ähnlich wie “Schlaf in CPP”

Weitere verwandte Antworten zu “Schlaf in CPP” auf C++

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen