1. 程式人生 > >linux下c++sleep函數

linux下c++sleep函數

names body linux下 stdout style 結果 fflush pos sleep函數

#include <iostream> 
#include <unistd.h>
using namespace std;

int main(){
    int i;
    char x[300];
    memset(x,0,300);
    for(i=0;i<10;i++){
        sprintf(&x[0],"%2d",i);
        x[2]=%;
        x[3+i]==;
        printf("\r%s>",x);
        fflush(stdout);
        sleep(1);
    }
    printf(
"\n"); // cout << "test1" << endl; // sleep(2); // cout << "test2" << endl; }

sleep() 秒級

usleep() 微秒級

輸出結果:

技術分享圖片

linux下c++sleep函數