473,406 Members | 2,293 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,406 software developers and data experts.

terminal progress indicator

Can anybody give me an example on how to write a progress indicator in C++
using the standard library cerr or cout?

My problem is I do not know how reset the output stream to the beginning of
the line, so just that information will do fine.

Thanks - Koen

Jul 22 '05 #1
10 2961
I don't think that c++ has anything like that. You could possibly use
either a carriage return char(13) (without the line feed) or use backspace
char(8) to backspace your way back to the end of the line (backspace doesn't
remove the character from the screen, it only moves the cursor back you
would have to print a space to remove the char). to go back one char cout <<
char(8) << char(' ') << char(8).
If you're program is going to only run on a PC you can use a bit of assembly
to move the cursor around on the screen. There are a couple of functions
for interrupt 21 that let you control the cursor.

Ali R.

"Koen Janssens" <kg*****@sandia.gov> wrote in message
news:BBE927F3.2E2D%kg*****@sandia.gov...
Can anybody give me an example on how to write a progress indicator in C++
using the standard library cerr or cout?

My problem is I do not know how reset the output stream to the beginning of the line, so just that information will do fine.

Thanks - Koen

Jul 22 '05 #2
"Koen Janssens" <kg*****@sandia.gov> wrote...
Can anybody give me an example on how to write a progress indicator in C++
using the standard library cerr or cout?

My problem is I do not know how reset the output stream to the beginning of the line, so just that information will do fine.


Outputting '\n' is a common way to begin a new line (the name of the
character is "newline"). However, there is no system-independent way
to "reset to output stream to the beginning of the line". Many of
the systems respond to '\r' as you probably expect, but that's _not_
guaranteed to be portable.

Victor
Jul 22 '05 #3
"Koen Janssens" <kg*****@sandia.gov> wrote in message
news:BBE927F3.2E2D%kg*****@sandia.gov...
Can anybody give me an example on how to write a progress indicator in C++
using the standard library cerr or cout?

My problem is I do not know how reset the output stream to the beginning of the line, so just that information will do fine.


Use a carriage return ("\r") instead of a newline ("\n")
Jul 22 '05 #4
"Ali R." <no****@company.com> wrote...
I don't think that c++ has anything like that. You could possibly use
either a carriage return char(13) (without the line feed) or use backspace
char(8) to backspace your way back to the end of the line (backspace doesn't remove the character from the screen, it only moves the cursor back you
would have to print a space to remove the char). to go back one char cout << char(8) << char(' ') << char(8).
Just a comment: code-independent names of those characters are \r
and \b, respectively. They are only 13 and 8 in ASCII, and ASCII
is not the only code around. And not on all systems they produce
the described effect, mind you.
If you're program is going to only run on a PC you can use a bit of assembly to move the cursor around on the screen. There are a couple of functions
for interrupt 21 that let you control the cursor.
Being on PC is not enough for that. You're apparently talking of
[MS-]DOS, a horribly outdated and notoriously dangerous platform,
or any of its emulators. Perhaps you should move your discussion
to comp.os.msdos.programmer...

Ali R.

"Koen Janssens" <kg*****@sandia.gov> wrote in message
news:BBE927F3.2E2D%kg*****@sandia.gov...
Can anybody give me an example on how to write a progress indicator in C++ using the standard library cerr or cout?

My problem is I do not know how reset the output stream to the beginning

of
the line, so just that information will do fine.

Thanks - Koen


Jul 22 '05 #5

"Koen Janssens" <kg*****@sandia.gov> wrote in message
news:BBE927F3.2E2D%kg*****@sandia.gov...
Can anybody give me an example on how to write a progress indicator in C++
using the standard library cerr or cout?

My problem is I do not know how reset the output stream to the beginning of the line, so just that information will do fine.


#include <iostream>
#include <string>
#include <time.h>

void delay(double seconds)
{
time_t start(time(0));

if(start != -1)
while((seconds - difftime(time(0), start)))
;
}

void reset(unsigned int count)
{
std::cout << '\r'
<< std::string(count, ' ')
<< '\r';
}

int main()
{
const unsigned int passes(3);
const unsigned int stars(10);
char c(0);

for(unsigned int i = 0; i < passes; ++i)
{
for(unsigned int j = 0; j < stars; ++j)
{
delay(1);
std::cout << (c = '0' + i + 1);
}

reset(stars);
}

return 0;
}
-Mike
Jul 22 '05 #6

"Mike Wahler" <mk******@mkwahler.net> skrev i en meddelelse
news:fx*******************@newsread1.news.pas.eart hlink.net...

[snip]
int main()
{
const unsigned int passes(3);
const unsigned int stars(10);
char c(0);

for(unsigned int i = 0; i < passes; ++i)
{
for(unsigned int j = 0; j < stars; ++j)
{
delay(1);
std::cout << (c = '0' + i + 1);
}

reset(stars);
}

return 0;
}
-Mike


Just out of curiosity.... what is this "reset(stars);" about - i do not
understand it and haven't seen it before.

/Peter
Jul 22 '05 #7
Koen Janssens wrote:
Can anybody give me an example on how to write a progress indicator in C++
using the standard library cerr or cout?

My problem is I do not know how reset the output stream to the beginning of
the line, so just that information will do fine.

Thanks - Koen


In days before windowing, my fellow programmers would output the
sequence:
'|'
"\b \b/"
"\b \b-"
"\b \b\\"
also known as a propeller.

Simpler versions use "*", "\b ", "\b*", ...
This is known as a heartbeat indicator.

Usually in the embedded world, we pursuade the hardware
folk to give us an LED to play with and use that as a
heartbeat indicator.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

Jul 22 '05 #8

"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:SjRwb.230097$9E1.1254971@attbi_s52...
"Ali R." <no****@company.com> wrote...
I don't think that c++ has anything like that. You could possibly use
either a carriage return char(13) (without the line feed) or use backspace char(8) to backspace your way back to the end of the line (backspace doesn't
remove the character from the screen, it only moves the cursor back you
would have to print a space to remove the char). to go back one char cout <<
char(8) << char(' ') << char(8).


Just a comment: code-independent names of those characters are \r
and \b, respectively. They are only 13 and 8 in ASCII, and ASCII
is not the only code around. And not on all systems they produce
the described effect, mind you.

Thanks for point that out.

If you're program is going to only run on a PC you can use a bit of

assembly
to move the cursor around on the screen. There are a couple of functions for interrupt 21 that let you control the cursor.


Being on PC is not enough for that. You're apparently talking of
[MS-]DOS, a horribly outdated and notoriously dangerous platform,
or any of its emulators. Perhaps you should move your discussion
to comp.os.msdos.programmer...


You are absolutely correct. If it's only going to run on a windows based
machine, SetConsoleCursorPosition would be a much better choice.


Jul 22 '05 #9

"Peter Koch Larsen" <pk*@mailme.dk> wrote in message
news:3f***********************@dread11.news.tele.d k...

"Mike Wahler" <mk******@mkwahler.net> skrev i en meddelelse
news:fx*******************@newsread1.news.pas.eart hlink.net...

[snip]
int main()
{
const unsigned int passes(3);
const unsigned int stars(10);
char c(0);

for(unsigned int i = 0; i < passes; ++i)
{
for(unsigned int j = 0; j < stars; ++j)
{
delay(1);
std::cout << (c = '0' + i + 1);
}

reset(stars);
}

return 0;
}
-Mike


Just out of curiosity.... what is this "reset(stars);" about - i do not
understand it and haven't seen it before.


It's just a function I wrote. I sends a carriage return
followed by a specified number of space characters to the
output stream. Nothing 'magical' about it.

-Mike
Jul 22 '05 #10

"Mike Wahler" <mk******@mkwahler.net> skrev i en meddelelse
news:OK*******************@newsread1.news.pas.eart hlink.net...

"Peter Koch Larsen" <pk*@mailme.dk> wrote in message
news:3f***********************@dread11.news.tele.d k...

"Mike Wahler" <mk******@mkwahler.net> skrev i en meddelelse
news:fx*******************@newsread1.news.pas.eart hlink.net...

[snip]
int main()
{
const unsigned int passes(3);
const unsigned int stars(10);
char c(0);

for(unsigned int i = 0; i < passes; ++i)
{
for(unsigned int j = 0; j < stars; ++j)
{
delay(1);
std::cout << (c = '0' + i + 1);
}

reset(stars);
}

return 0;
}
-Mike


Just out of curiosity.... what is this "reset(stars);" about - i do not
understand it and haven't seen it before.


It's just a function I wrote. I sends a carriage return
followed by a specified number of space characters to the
output stream. Nothing 'magical' about it.

-Mike


Hi Mike....

Just reread your original answer - and there it was. I must have been blind!

Thanks
Peter
Jul 22 '05 #11

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

Similar topics

4
by: Ron | last post by:
I spent the last couple of days setting up a progress indicator for a private site that only does a couple uploads a day. After figuring out there was no way to set the 'upload_tmp_dir' or...
1
by: Anonieko | last post by:
Query: How to display progress bar for long running page Answer: Yet another solution. REFERENCE: http://www.eggheadcafe.com/articles/20050108.asp My only regret is that when click the...
1
by: Chris | last post by:
Hi, I had asked this question on the asp website but no ans. How can I move the Atlas Progress Indicator on a page. It seems to default only to the top. I have three textbox and a button on a...
1
by: Marko Vuksanovic | last post by:
I am trying to implement a file upload progress indicator (doesn't have to be a progress bar) using atlas... I do realize that the indicator cannot be implemented using Update panel control, but is...
6
by: Marko Vuksanovic | last post by:
I am trying to implement a file upload progress indicator (doesn't have to be a progress bar) using atlas... I do realize that the indicator cannot be implemented using Update panel control, but is...
1
by: Marko Vuksanovic | last post by:
I used the following code for implementing a file upload progress indicator, using UpdateProgress Panel, though I have a problem that FileUpload.Has File always returns false. Any suggestions what...
10
by: Robertf987 | last post by:
Okay, now then. I'm hoping somebody can help here, pretty please. I want to make a progress bar/indicator on a form. At first I was just going to insert an animated gif, but I've tried and remembered...
1
by: Rajarshi | last post by:
Hi, I have a web application built using mod_python.Currently it behaves like a standard CGI - gets data from a form, performs a query on a backend database and presents a HTML page. However the...
0
by: shehzadmajeed | last post by:
I am a Point of Sale Terminal Programmer/Developer and currently assigned to develop a VTI Simulator (Virtual Terminal Interface) than can exchange messages as per Specification through RS232-COM...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.