"Freeze up" the program for awhile

Ok, so here's sort of what I'm trying to accomplish. I'll try to make it as understandable as I know how.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
int main()
{
int num;

Start:
cout << "\nEnter an integer: ";
cin >> num;

if ( num < 0 )
{
Sleep(3000);
fflush(stdin); // To make sure the input stream is completely clear
goto Start;
}

cout << "\nThis is what you typed: " << num;

return 0;
}



The problem is that even though I've already cleared the input stream after the "Sleep" statement, whatever I typed while the program was sleeping is still there. I've tried to use "cin.ignore(80,'\n')", too, but of course, that wouldn't make any difference!
So does anyone get an idea how to fix this?

Thanks in advance!
Does it compile? I thought fflush is for FILE* structs?

Anyway.. without having tried it, I would go for "while (stdin) stdin.get();"

Ciao, Imi.
Umm.... I tried "stdin.get()" like you said. But it doesn't work! ... stdin is not an object.

Anyways, what I was trying to do is to actually pause the program for a certain amount of time. I also want to make sure that if I randomly type something on the keyboard while the programing is "sleeping", these characters wont retain after the program wakes up.
So if you know a better the way, I'd love to hear.

Thanks!
Last edited on
What imi ment, i guess, is that stdin is an speudo for your standard input stream (in your case extern istream cin)
Last edited on
yea.. stupid me. "cin", not "stdin".

Ciao, Imi
Topic archived. No new replies allowed.