animation blinker effect

Here's my code so far(copy and paste it to see what it does).
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <conio.h>
#include <windows.h>

using namespace std;

void z() {Sleep(500);}

char x[6] = {1,2,1,2,1,2};

int main(){
    for (int i=0;i<6;i++)
    {
        cout << x[i];
        z();
    }
getch();
return 0;
}

I want it to clear away ☺ and ☻ after they're displayed so I kind of have a "blinking" effect. How would I do this?
You could use a \b (backspace) char. Outputting after your sleep should work.

And \r can be used to go back to the start of the current line.

Andy

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <conio.h>
#include <windows.h>

using namespace std;

void z() {Sleep(500);}

char x[6] = {1,2,1,2,1,2};

int main(){
    for (int i=0;i<6;i++)
    {
        cout << x[i];
        z();
        cout << '\b'; // backspace - move back one char
    }
getch();
return 0;
}
Last edited on
THANKS!!! ^That code works JUST how I wanted it to!
Topic archived. No new replies allowed.