Expand|Select|Wrap|Line Numbers
- const char DONE = '=';
- const char BLANK = ' ';
- const unsigned INCREMENT = 3;
- static char progressB[(100 / INCREMENT ) + INCREMENT ] = "[ ]";
- void progress(unsigned int current, char* msg)
- {
- // Work out how many blocks are empty and full
- unsigned int blocks = current / INCREMENT;
- unsigned int remaining = 100 / INCREMENT;
- unsigned int i = 0;
- // All the 'DONE' blocks on progress bar
- while( i < blocks)
- progressB[++i] = DONE;
- // All the 'TO-DO' blocks on progress bar
- while(i < remaining)
- progressB[++i] = BLANK;
- // We print the percentage before the progress bar, but we
- // don't want the bar jigging around as the number of digits
- // change so adjust the number of spaces we use.
- if (current < 10)
- printf(" %u%% ", current);
- else if (current == 100)
- printf(" %u%% ", current);
- else
- printf(" %u%% ", current);
- // Print the progress bar
- printf( "%30s", progressB);
- // Print the message (e.g. What action are we doing?)
- printf(msg);
- // Carriage return, so we can re-print the progress bar next time around
- printf("\r");
- }
If I add "cout << endl;" before or after this function gets called then it starts printing out the progress bar. If I use cout without an std::endl then I still get no output. Obviously introducing the endl is bad however because my progress bar then looks like so:
0% [ ]Import File
9% [=== ] Importing File
18% [====== ] Importing File
On seperate lines. Any help to figure out why this is happening would be much appreciated.
Thanks!