Progressbar

Does anyone have a code for an console progressbar.. I would write it myself, if i knew how i should it should print the amount in procent and show it using the progressbar ..
Last edited on
Boring suggestion :
A progress bar is suggested only if you have some data to process before any user interaction of any kind is required. And the 'process' must take long enough (maybe like 10 secs) so that you have time to display it.

Interesting suggestion :
But in case you need it or just want it for fun, you can do it like this(there are many ways of doing this I guess, and please note that this is merely a suggestion):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
#include <Windows.h>

using namespace std;

void ProgressBar(float TIME)		
{
	int bar = 219;
	char bar_Char = bar;

	float t_i = 0, t_f = TIME;
	
	while(t_i != t_f)
	{
		for(int i = t_i; i < t_f; i++)
			cout << bar_Char;
		Sleep(TIME * 100);
		t_i += 0.5;
	}

	cout << endl;
}

int main()
{
	float delay_time = 6.0f;
	cout << "\nProgress:-\n" << endl;
	ProgressBar(delay_time);
	system("cls");
	cout << "\nComplete!" << endl;

	cout << endl;
	system("pause");
	return 0;
}


Run and see what you get ;)
Last edited on
@JLBorges

Does that mean the use of progress bars is totally deprecated or only the boost::progress_display is deprecated?
Only the Boost version 1 timers are deprecated.

Rationale is at the top of the page linked to earlier.
@JLBorges

Ok, I understand it now.
I want to implement one for a for loop, so i can see how far the program is in the nested for -loop..
In the boost page linked to earlier, there is an example which reports progress during the execution of a for loop.
How do i include it?
Download boost from here: http://www.boost.org/users/download/#live

And then, with the directory containing boost added to the set of directories that the compiler searches for include files:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <boost/progress.hpp>

volatile double value = 0.0 ;
volatile int j = 0 ;

int main()
{
    const int N_OUTER = 10 ;
    const int N = 1024*1024*64 ;

    boost::progress_display progress(N_OUTER) ;

    for( int i = 0 ; i < N_OUTER ; ++i )
    {
        for( j = 0 ; j < N ; ++j )
        {
            if( j%2 == 1 ) value *= 1.23 ;
            else value /= 1.23 ;
        }

        ++progress ; // report progress
    }
}

Topic archived. No new replies allowed.