1

I'm looking for a universal sleep command and also a universal pause command for C++. It needs to work for Windows, MAC, and Linux computers. If anyone knows of any great portability command, please let me know.

3
  • 2
    std::this_thread::sleep_for(std::milli(1000)) Commented Oct 21, 2014 at 18:10
  • By pause, do you mean pause at the console? Commented Oct 21, 2014 at 18:22
  • On the console pause, stackoverflow.com/q/24776262/3747990 Commented Oct 21, 2014 at 18:31

1 Answer 1

6

C++ 11 has

std::this_thread::sleep_for(std::chrono::milliseconds(1000)); 

and C++14 has

using namespace std::literals; std::this_thread::sleep_for(1000ms); 

as @Creris mentioned Boost has you covered for C++03 on Win32 and platforms that have pthreads

boost::this_thread::sleep_for(boost::chrono::milliseconds(1000)); 
Sign up to request clarification or add additional context in comments.

1 Comment

just to add, if your compiler doesnt support C++11, you are out of luck for standard solution, but I believe boost has boost::thread that works on C++03 on multiple platforms

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.