The terminal outputs progress information in the same row.

Source: Internet
Author: User

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}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.