By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,778 Members | 2,015 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,778 IT Pros & Developers. It's quick & easy.

Displaying progress dots in ANSI C++

P: n/a
Hello everyone,

I was wondering if (in pure command line, "non-visual" C++) there is a
simple way of regularly calling an output function in the background
while a process, e.g. loading of a huge file, is running. I am thinking
of displaying a classical

Loading.....

output where every second a new dot is displayed, for instance, maybe
starting anew after 10 dots or something.

I hope this is the appropriate group to post to...thanks for your help,
ambros

Jun 16 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
am*************@googlemail.com wrote:
I was wondering if (in pure command line, "non-visual" C++) there is a
simple way of regularly calling an output function in the background
while a process, e.g. loading of a huge file, is running. I am
thinking of displaying a classical

Loading.....

output where every second a new dot is displayed, for instance, maybe
starting anew after 10 dots or something.

I hope this is the appropriate group to post to...thanks for your
help, ambros


int iteration = 0;
... // long process start
if (figure_out_that_another_second_passed)
{
int ndots = ++iteration % 10;
std::cout << "\rLoading" << std::string(ndots, '.');
std::cout.flush();
}

There is no other way. If your OS supports threading, you could try
doing output in another thread and synchronize them somehow, but C++
language doesn't define any threading, you need to ask in another NG,
line one that's dedicated to your OS.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 16 '06 #2

P: n/a
am*************@googlemail.com wrote:
Hello everyone,

I was wondering if (in pure command line, "non-visual" C++) there is a
simple way of regularly calling an output function in the background
while a process, e.g. loading of a huge file, is running. I am thinking
of displaying a classical

Loading.....

output where every second a new dot is displayed, for instance, maybe
starting anew after 10 dots or something.

I hope this is the appropriate group to post to...thanks for your help,
ambros


The traditional way is to put a callback function in the lengthy
function that voluntarily calls the callback every so often. For
example you can print a spinning line / - \ | followed by backspace
each time. Otherwise you have to descend into threads, and lose the
useful property of knowing that the code has not crashed.

Jun 16 '06 #3

P: n/a
On Fri, 16 Jun 2006 08:05:34 -0700, ambros.gleixner wrote:
I was wondering if (in pure command line, "non-visual" C++) there is a
simple way of regularly calling an output function in the background while
a process, e.g. loading of a huge file, is running. I am thinking of
displaying a classical

Loading.....

output where every second a new dot is displayed, for instance, maybe
starting anew after 10 dots or something.


I suggest instead of making it time-based, making it progress-based. For
example,

bool incremental_load()
{
// Load logical chunk of data from large file
// Return false if this is the last chunk, false if
// more data left.
}

void update_spinner()
{
// Can be as fancy as you want. Here, just print dots.
std::cout << ".";
}

void main_loop()
{
while (incremental_load())
update_spinner();
}

Gregg

Jun 17 '06 #4

P: n/a
Thank you all for your quick comments! Sorry that I didn't repsond
immediately as I was held up the last days unexpectedly.
For what I'm trying to do it looks like I would have to start using
threads, and I am afraid that this wouldn't be worth the hassle for
just some fancy output. If I understood it correctly, it would also
make my programme platform dependent, which is a good thing to avoid. I
think I'll continue with constant dots. Thanks a lot for your advice,

ambrose

Jun 22 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.