首页 > 其他 > 详细

终端同一行输出进度信息

时间:2015-08-07 13:02:18      阅读:328      评论:0      收藏:0      [点我收藏+]
直接贴代码:

1
#define MYSIZE 32*1024*1024 2 3 #include <iostream> 4 #include <iomanip> 5 #include <fstream> 6 #include <pthread.h> 7 #include <stdlib.h> 8 #include <string.h> 9 #include <time.h> 10 #include <sys/time.h> 11 12 using namespace std; 13 14 unsigned int My_buffer[MYSIZE]; 15 16 string getFileName(); 17 18 int main(int argc, char **argv) 19 { 20 //out current thread id; 21 cout<<getpid()<<endl; 22 23 struct timeval tpseed; 24 int n; 25 float process; 26 float rule; 27 28 cout<<"Data Buffer is Creating ..."; 29 //clean output buffer 30 fflush(stdout); 31 //process step 32 rule=0.01; 33 34 for(n=0;n<MYSIZE;n++) 35 { 36 //get millionseconds 37 gettimeofday(&tpseed,NULL); 38 //get rand 39 srand(tpseed.tv_usec); 40 My_buffer[n]=(unsigned int)(1+(3000.0*rand())/(RAND_MAX+1.0)); 41 42 process=n/(MYSIZE/100.0); 43 44 if(n%(MYSIZE/100)==0 || ((int)process)<10) 45 { 46 if(process>rule) 47 { 48 rule=rule+0.01; 49 //clean outside char 50 cout<<"\r "; 51 /*output avaliable char 52 *\033[32;5m set fonts properties 53 * \033[0m set fonts nomal 54 */ 55 cout<<"\r\033[32;5m Data Buffer is Creating \033[31;1m" 56 <<setprecision(2)<<process<<"%\033[32;5m ...\033[0m"; 57 //clean output buffer 58 fflush(stdout); 59 } 60 } 61 } 62 cout<<endl; 63 return 0; 64 }

 

终端同一行输出进度信息

原文:http://www.cnblogs.com/teyond/p/4710274.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!