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

后端 未结 14 2167
情话喂你
情话喂你 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:33

    You can also use select(2) if you want microsecond precision (this works on platform that don't have usleep(3))

    The following code will wait for 1.5 second:

    #include 
    #include 
    #include `
    
    int main() {
        struct timeval t;
        t.tv_sec = 1;
        t.tv_usec = 500000;
        select(0, NULL, NULL, NULL, &t);
    }
    

    `

提交回复
热议问题