C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Printing progressbar

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
H?vard Sj?voll
Guest





PostPosted: Thu Jun 24, 2004 11:13 am    Post subject: Printing progressbar Reply with quote



Anyone got any code for how to print a progressbar in a console-window?

That is, - something like

"Loading: X%"

where X is continousely updated.

-håvard-
Back to top
Sree
Guest





PostPosted: Thu Jun 24, 2004 11:27 am    Post subject: Re: Printing progressbar Reply with quote




Standard C++ doesn't offer any way to do it. You have to refer to your system
related console programming manuals for it.

--
Use our news server 'news.foorum.com' from anywhere.
More details at: http://nnrpinfo.go.foorum.com/
Back to top
Unforgiven
Guest





PostPosted: Thu Jun 24, 2004 12:21 pm    Post subject: Re: Printing progressbar Reply with quote



"H?vard Sj?voll" <sjovoll (AT) orakel (DOT) ntnu.no> wrote

Quote:
Anyone got any code for how to print a progressbar in a console-window?

That is, - something like

"Loading: X%"

for( int x = 0; x <= 100; ++x )
{
std::cout << "Loading: " << x << "%r" << std::flush;
// do something
}

r without n sends the cursor back to the beginning of the line but not to
a new line, so you can overwrite the previous contents of the line. This is
afaik the only standards-compliant portable way to do it.

--
Unforgiven


Back to top
Victor Bazarov
Guest





PostPosted: Thu Jun 24, 2004 2:53 pm    Post subject: Re: Printing progressbar Reply with quote

H?vard Sj?voll wrote:
Quote:
Anyone got any code for how to print a progressbar in a console-window?

That is, - something like

"Loading: X%"

where X is continousely updated.

Something like

std::cout << "rLoading: " << Xvalue << '%';

The behaviour of your terminal when r is printed to it is of course
OS-specific, but it usually works the way you want it.

Don't forget to print 'std::endl' when you're done to move to the next
line.

Victor

Back to top
Allan Bruce
Guest





PostPosted: Thu Jun 24, 2004 3:45 pm    Post subject: Re: Printing progressbar Reply with quote


"Victor Bazarov" <v.Abazarov (AT) comAcast (DOT) net> wrote

Quote:
H?vard Sj?voll wrote:
Anyone got any code for how to print a progressbar in a console-window?

That is, - something like

"Loading: X%"

where X is continousely updated.

Something like

std::cout << "rLoading: " << Xvalue << '%';

The behaviour of your terminal when r is printed to it is of course
OS-specific, but it usually works the way you want it.

Don't forget to print 'std::endl' when you're done to move to the next
line.

Victor

If this doesnt work, another way I found was to use several b - so
basically:

for (int i=0; i std::cout << "b";
std::cout << "rLoading: " << Xvalue << '%';

Allan



Back to top
Mike Weller
Guest





PostPosted: Thu Jun 24, 2004 4:05 pm    Post subject: Re: Printing progressbar Reply with quote

Victor Bazarov wrote:

Quote:
H?vard Sj?voll wrote:

Anyone got any code for how to print a progressbar in a console-window?

That is, - something like
"Loading: X%"

where X is continousely updated.


Something like

std::cout << "rLoading: " << Xvalue << '%';

The behaviour of your terminal when r is printed to it is of course
OS-specific, but it usually works the way you want it.

Don't forget to print 'std::endl' when you're done to move to the next
line.

Victor

Yeah I think the best way to do this is with your final progress bar
dislpayed as, for example:

[0%...25%...50%...75%...100%]

And progressivly add a '.' or number to the end. Something like this:

//----------------------------
cout << "[";

for ( int x = 0; x <= 100; x++ )
{
if ( !( x % 20 ) ) // display every 20th number
cout << x << "%";
else if ( !( x % 5) ) // otherwise display a dot every 5 numbers
cout << ".";
}

cout << "]";
//----------------------------

Back to top
Mike Weller
Guest





PostPosted: Thu Jun 24, 2004 4:08 pm    Post subject: Re: Printing progressbar Reply with quote

Victor Bazarov wrote:

Quote:
H?vard Sj?voll wrote:

Anyone got any code for how to print a progressbar in a console-window?

That is, - something like
"Loading: X%"

where X is continousely updated.


Something like

std::cout << "rLoading: " << Xvalue << '%';

The behaviour of your terminal when r is printed to it is of course
OS-specific, but it usually works the way you want it.

Don't forget to print 'std::endl' when you're done to move to the next
line.

Victor

Yeah I think the best way to do this is with your final progress bar
dislpayed as, for example:

[0%...25%...50%...75%...100%]

And progressivly add a '.' or number to the end. Something like this:

//----------------------------
cout << "[";

for ( int x = 0; x <= 100; x++ )
{
if ( !( x % 20 ) ) // display every 20th number
cout << x << "%";
else if ( !( x % 5) ) // otherwise display a dot every 5 numbers
cout << ".";
}

cout << "]";
//----------------------------


Back to top
Owen Jacobson
Guest





PostPosted: Fri Jun 25, 2004 5:41 am    Post subject: Re: Printing progressbar Reply with quote

On Thu, 24 Jun 2004 16:45:44 +0100, Allan Bruce wrote:

Quote:

"Victor Bazarov" <v.Abazarov (AT) comAcast (DOT) net> wrote in message
news:9WBCc.1836$Jp.61538 (AT) ord-read (DOT) news.verio.net...
H?vard Sj?voll wrote:
Anyone got any code for how to print a progressbar in a console-window?

That is, - something like

"Loading: X%"

where X is continousely updated.

Something like

std::cout << "rLoading: " << Xvalue << '%';

The behaviour of your terminal when r is printed to it is of course
OS-specific, but it usually works the way you want it.

Don't forget to print 'std::endl' when you're done to move to the next
line.

Victor

If this doesnt work, another way I found was to use several b - so
basically:

for (int i=0; i std::cout << "b";
std::cout << "rLoading: " << Xvalue << '%';


Watch it with that. If you go too far backwards, some versions of Windows
(NT-based ones) will bluescreen spectacularly.

<http://homepages.tesco.net/~J.deBoynePollard/FGA/csrss-backspace-bug.html>

</platform-specific behaviour>

--
Some say the Wired doesn't have political borders like the real world,
but there are far too many nonsense-spouting anarchists or idiots who
think that pranks are a revolution.


Back to top
Unforgiven
Guest





PostPosted: Mon Jun 28, 2004 12:30 pm    Post subject: Re: Printing progressbar Reply with quote

"Owen Jacobson" <angstrom (AT) lionsanctuary (DOT) net> wrote

Quote:
On Thu, 24 Jun 2004 16:45:44 +0100, Allan Bruce wrote:


"Victor Bazarov" <v.Abazarov (AT) comAcast (DOT) net> wrote in message
news:9WBCc.1836$Jp.61538 (AT) ord-read (DOT) news.verio.net...
H?vard Sj?voll wrote:
Anyone got any code for how to print a progressbar in a
console-window?

That is, - something like

"Loading: X%"

where X is continousely updated.

Something like

std::cout << "rLoading: " << Xvalue << '%';

The behaviour of your terminal when r is printed to it is of course
OS-specific, but it usually works the way you want it.

Don't forget to print 'std::endl' when you're done to move to the next
line.

Victor

If this doesnt work, another way I found was to use several b - so
basically:

for (int i=0; i std::cout << "b";
std::cout << "rLoading: " << Xvalue << '%';

platform-specific behaviour

Watch it with that. If you go too far backwards, some versions of Windows
(NT-based ones) will bluescreen spectacularly.

http://homepages.tesco.net/~J.deBoynePollard/FGA/csrss-backspace-bug.html

/platform-specific behaviour

Yup. The bug was fixed in Windows 2000 SP3 and Windows XP SP1. In NT4 it'll
remain a bug forever.

--
Unforgiven


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.