Question

You may have seen in many places "Loading..." where the 3 dots(or more), viz. "...", first appear one by one, then after displaying all the dots, they disapperar and once again appear one by one (so, total 2 times).

To elaborate:-

Stage 1:

Loading.

Stage 2:

Loading..

Stage 3:

Loading...

Then, it repeats second time! and then terminate!

So, for this I prepared a C++ program and its source code is:

#include <iostream.h>
#include <time.h>
#include<dos.h>
int main()
{
    cout << "Loading";
    cout.flush();
    for (;;) {
        for (int i = 0; i < 3; i++) {
            cout << ".";
            cout.flush();
            sleep(1);
        }
        cout << "\b\b\b   \b\b\b";
    }

    return 0;
}

This program is not terminating. It doesn't stops! How can I edit this to make this terminate?

Please post codes supported by Turbo C++ Compiler, as I am not too much aware of the ANSI C++!! :P

Gguys, please help me out? :)

Thanks, in advance! :)

Was it helpful?

Solution 2

I'd go for the following solution using "carriage return":

for (int j = 0; j < 3; j++) {
   cout << "\rLoading   \rLoading";
   for (int i = 0; i < 3; i++) {
      cout << ".";
      sleep(300);
   }
}

This overwrites the current line (with all dots) and repostions cursor at the end of "Loading".

BTW, the sleep value here is in milliseconds. You may have to change that if yours is in seconds.

Also, in your program you have nested loops both with running i - I doubt that this will work as intended...

OTHER TIPS

Why not delete those points using a backspace?

#include <iostream>
#include <ctime>

using namespace std;

int main()
{
    cout << "Loading";
    cout.flush();
    for (;;) {
        for (int i = 0; i < 3; i++) {
            cout << ".";
            cout.flush();
            sleep(1);
        }
        cout << "\b\b\b   \b\b\b";
    }

    return 0;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top