473,399 Members | 3,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Printing progressbar

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-
Jul 22 '05 #1
8 15073
"H?vard Sj?voll" <sj*****@orakel.ntnu.no> wrote in message
news:2f**************************@posting.google.c om...
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

Jul 22 '05 #2
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
Jul 22 '05 #3

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/
Jul 22 '05 #4

"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:9W*****************@ord-read.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<LengthOfProgressInChars; i++)
std::cout << "\b";
std::cout << "\rLoading: " << Xvalue << '%';

Allan
Jul 22 '05 #5
Victor Bazarov wrote:
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 << "]";
//----------------------------
Jul 22 '05 #6
Victor Bazarov wrote:
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 << "]";
//----------------------------

Jul 22 '05 #7
On Thu, 24 Jun 2004 16:45:44 +0100, Allan Bruce wrote:

"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:9W*****************@ord-read.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<LengthOfProgressInChars; 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>

--
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.

Jul 22 '05 #8
"Owen Jacobson" <an******@lionsanctuary.net> wrote in message
news:pa****************************@lionsanctuary. net...
On Thu, 24 Jun 2004 16:45:44 +0100, Allan Bruce wrote:

"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:9W*****************@ord-read.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<LengthOfProgressInChars; 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

Jul 22 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Daniel Pryde | last post by:
Hi there. I hope this isn't a stupid question to ask, but does anyone know how to print out a string without moving to a new line each time and simply updating the first line. An example would be,...
0
by: Bill | last post by:
Hi all, I have developed a component to wrap MS-Word, and I use this to manage my reports. It´s a simple components, but it´s very useful...to eliminate this very tiresome declarations like...
2
by: jez123456 | last post by:
Hi, thanks for the previous advice on progressbars with showing the percentage. I would now like to create a less clunky version. I.e at the moment my progressbar shows 7 separate steps. Some...
8
by: needin4mation | last post by:
Please consider: foreach (ListViewItem item in listViewFiles.Items) { // Display the ProgressBar control. pBar1.Visible = true; // Set Minimum to 1 to represent the first file being copied....
1
by: Mehr H | last post by:
I've been trying to figure out how i can embed a Windows.Forms.ProgressBar in my webform (aspx) file. I have tried putting a Windows.Forms.ProgressBar as public on a regular winform designer form...
3
by: Mitchell Vincent | last post by:
In other programming languages I've been able to easily change the style of a progress bar between smooth and blocked. I find that is either really hidden or impossible in .NET. Am I missing...
1
by: nobody | last post by:
Hi I'm currently developing a Windows application. At the start of the application I load several tables into datatables in a dataset. I also use a progressbar to show the user how much percent...
2
by: =?Utf-8?B?QWFyb24=?= | last post by:
Since some controls such as the DataGridView take a long time to update themselves when performing certain tasks, I have added a StatusStrip with a ProgressBar on it. While I am updating the...
4
by: sivamoorthy | last post by:
how to use a progressbar in a one cpp file but defined in another header file. the function in which i am using is a static member function. how to use the progressbar inside the function ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.