Pause program execution for 5 seconds in c++

前端 未结 2 1096
醉梦人生
醉梦人生 2020-12-15 01:06

I want to pause the execution of c++ program for 5 seconds. In android Handler.postDelayed has the required functionality what I am looking for. Is there anything similar to

2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-15 01:45

    #include 
    #include 
    #include 
    
    int main()
    {
        std::cout << "Hello waiter" << std::endl;
        std::chrono::seconds dura( 5);
        std::this_thread::sleep_for( dura );
        std::cout << "Waited 5s\n";
    }
    

    this_thread::sleep_for Blocks the execution of the current thread for at least the specified sleep_duration.

提交回复
热议问题