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.
1 Answer
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)); 1 Comment
Creris
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
std::this_thread::sleep_for(std::milli(1000))