How do you add a timed delay to a C++ program?

后端 未结 14 2104
情话喂你
情话喂你 2020-11-28 02:11

I am trying to add a timed delay in a C++ program, and was wondering if anyone has any suggestions on what I can try or information I can look at?

I wish I had more

相关标签:
14条回答
  • 2020-11-28 02:40

    On Windows you can include the windows library and use "Sleep(0);" to sleep the program. It takes a value that represents milliseconds.

    0 讨论(0)
  • 2020-11-28 02:44

    You can try this code snippet:

    #include<chrono>
    #include<thread>
    
    int main(){
        std::this_thread::sleep_for(std::chrono::nanoseconds(10));
        std::this_thread::sleep_until(std::chrono::system_clock::now() + std::chrono::seconds(1));
    }
    
    0 讨论(0)
提交回复
热议问题