The terminal outputs progress information in the same row.
Directly paste the Code:
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 buffer30 fflush (stdout); 31 // process step32 rule = 0.01; 33 34 for (n = 0; n <MYSIZE; n ++) 35 {36 // get millionseconds37 gettimeofday (& tpseed, NULL); 38 // get rand39 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 char50 cout <"\ r "; 51/* output avaliable char52 * \ 033 [32; 5 m set fonts properties 53 * \ 033 [0 m set fonts nomal54 */55 cout <"\ r \ 033 [32; 5 m Data Buffer is Creating \ 033 [31; 1 m "56 <setprecision (2) <process <" % \ 033 [32; 5 m... \ 033 [0 m "; 57 // clean output buffer58 fflush (stdout); 59} 60} 61} 62 cout <endl; 63 return 0; 64}