linux下c++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() 微秒级

输出结果:

 

 

 


posted @ 2018-02-23 14:12  Ryan_zheng  阅读(2453)  评论(0编辑  收藏  举报