How to flush all?

I'm not quite sure what to do here. This is code for a Simon style game, and while currently pretty functional (and with GUI pending) I can't get the entire sequence to flush. It flushes the most recent output only. I've tried flushall and multiple << flush but these simply don't work.

I'm utterly clueless.

Any help appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
 #include <iostream>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <windows.h>

using namespace std;
int main () {

string seq = "";
string userseq = "";
char color[4];
color[0]='Y';
color[1]='G';
color[2]='R';
color[3]='B'; // These represent Yellow, Green, Red, Blue.
int round;
round=1;
srand(time(NULL)); // 'True' randomness using time as a seed.

	while (round<51){


seq +=color[rand()%4];




cout << seq << flush;
Sleep(2000);
//cout << flush << endl;
cout << "\010." << flush << '\n';


cout << "Enter " << round << " characters: ";
cin >> userseq;


if (userseq != seq){
cout << " The correct sequence was: " << seq << endl;
break;
}




if (round == 50){
cout << "50 rounds reached! Congratulations!";
break;
}
round++;
}




cin.get();


	return 0;


}
Flush in this case just means that everything that you have written to cout is made visible. To overwrite the sequence that you have printed I think you will have to print the '\010' char (or '\b') as many times as the number of colours in the sequence and print equally many dots.
If you're trying to clear the screen like Peter87 suggests then since you're already including windows.h I can assume you have no trouble including wincon.h as well. Here is some code to read over:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
void Clear()
{
    HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);

    CONSOLE_SCREEN_BUFFER_INFO conBuf;
    /* http://msdn.microsoft.com/en-us/library/windows/desktop/ms682093(v=vs.85).aspx */
    COORD Start = {0,0};
    
    GetConsoleScreenBufferInfo(hOut, &conBuf);
    /* http://msdn.microsoft.com/en-us/library/windows/desktop/ms683171(v=vs.85).aspx */
    
    FillConsoleOutputCharacter(hOut, ' ', (conBuf.dwSize.X * conBuf.dwSize.Y), Start, NULL);
    /* http://msdn.microsoft.com/en-us/library/windows/desktop/ms682663(v=vs.85).aspx */
    
    SetConsoleCursorPosition(hOut, Start);
    /* http://msdn.microsoft.com/en-us/library/windows/desktop/ms686025(v=vs.85).aspx */
    
    return;
}


EDIT: This is some copy pasta from a console "game" I was playing around with about a year ago. In my version I made 'hOut' a global variable since it was needed elsewhere and it didn't make sense to keep grabbing it and\or passing it around every time I wanted to clear the screen or what ever, that's why it isn't closed as would normally be the case.
Last edited on
Topic archived. No new replies allowed.