Search
 
SCRIPT & CODE EXAMPLE
 

CPP

C++ pause program

#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

c++ pause

#include <Windows.h>

int main() {
	//do stuff
	system("Pause");
}
Comment

How to pause a c++ program.

//On windows.
#include<windows.h>
Sleep(milliseconds);

//On linux.
#include<unistd.h>
unsigned int microsecond = 1000000;
usleep(3 * microsecond);//sleeps for 3 second

// c++ 11 for high resulution.

#include <chrono>
#include <thread>

int main() {
    using namespace std::this_thread; // sleep_for, sleep_until
    using namespace std::chrono; // nanoseconds, system_clock, seconds

    sleep_for(nanoseconds(10));
    // or 
    sleep_until(system_clock::now() + seconds(1));
}

// C++ 14 for high resuluton.

#include <chrono>
#include <thread>

int main() {
    using namespace std::this_thread;     // sleep_for, sleep_until
    using namespace std::chrono_literals; // ns, us, ms, s, h, etc.
    using std::chrono::system_clock;

    sleep_for(10ns);
  	// or
    sleep_until(system_clock::now() + 1s);
}
Comment

c++ pause

system("pause");
Comment

PREVIOUS NEXT
Code Example
Cpp :: int_min in cpp 
Cpp :: c++ flush stdin 
Cpp :: add arbitrum to metamask 
Cpp :: for vector c++ 
Cpp :: compile cpp with specific version 
Cpp :: C++ system text format 
Cpp :: remove all element of vector c++ 
Cpp :: c++ fill array with 0 
Cpp :: c++ pi 
Cpp :: eosio parse string 
Cpp :: how to iterate in string in c++ 
Cpp :: multiply image mat by value c++ 
Cpp :: error: Microsoft Visual C++ 14.0 is required. Get it with "Build Tools for Visual Studio": https://visualstudio.microsoft.com/downloads/ 
Cpp :: c++ index of nth occurence 
Cpp :: c++ make constructor fails if bad argument 
Cpp :: how to make a sqlite3 object in cpp 
Cpp :: factore of 20 in c+ 
Cpp :: convert vector to set c++ 
Cpp :: c++ uniform_real_distribution get same result 
Cpp :: remove () not working c++ 
Cpp :: prime number program 
Cpp :: qstring to char* 
Cpp :: how to delete a certain amount of numbers of the same value in multiset c++ 
Cpp :: spicoli 
Cpp :: fabs() c++ 
Cpp :: sort function from bigest to smallest c++ 
Cpp :: taking a vector in c++ containing element 
Cpp :: how to clear console c++ 
Cpp :: c++ hours minutes seconds 
Cpp :: scan line in c++ 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =