flush statement

Can anyone tell me how to use the flush statement? Please write me a hello world program that displays "Hello World!" for 1 second (you might need to use the sleep statement too) and then clears it away from the screen. Thx!
"flush" as in "make sure that everything I have been putting into buffered output stream are sent to where-ever that stream flows to"?
http://www.cplusplus.com/reference/ostream/ostream/flush/

Clearing something away from "screen" is something different.
Well then, how do I clear something from the screen? Here's my code so far:
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] = {'h','e','l','l','o','!'};

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

It displays "hello!" by individualy typing each letter. What I ACTUALLY want it do is to clear each letter right after it is typed. How do I do this?
Last edited on
Like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
void Clear()
{
    HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_SCREEN_BUFFER_INFO conBuf;
    COORD Start = {0,0};

    GetConsoleScreenBufferInfo(hOut, &conBuf);
    FillConsoleOutputCharacter(hOut, ' ', (conBuf.dwSize.X * conBuf.dwSize.Y), Start, NULL);
    SetConsoleCursorPosition(hOut, Start);

    CloseHandle(hOut);
    return;
}


EDIT: Normally we don't just dump code like this. But this is a common question with an answer that takes beginners at least an hour of research to understand assuming they don't get discouraged so I made a personal exception.
Last edited on
I don't want to just dump the code! I want to have it so you just won't see it for a small period of time, and then it can be reused later in the program. How would I do this?
Can somebody help? Please?
Topic archived. No new replies allowed.