Re: Clearing the input buffer - then pausing
- From: "Frank Hickman [MVP]" <fhickman_NOSP@xxxxxxxxxxxxxxx>
- Date: Sat, 9 Apr 2005 04:33:03 -0400
"Ray Mitchell" <RayMitchell_NOSPAM_@xxxxxxxxxxxxxxxxxx> wrote in message
news:64F0E2AE-5B41-49E7-B015-8A3283CA803C@xxxxxxxxxxxxxxxx
> VS .NET 2003: I should know this, but I don't! I would like to pause my
> program at some arbitrary point and resume only when the Enter key is
> pressed
> once (preceeded by zero or more other characters). The code below works
> if I
> do not comment out the first cin line. If I do, however, it takes two
> strokes of the Enter key. What appears to be happening is that the
> ignore
> method does not operate on a new buffer, but that's just a guess. I've
> tried
> several different things but it has become painfully clear that I should
> consider another line of work! Additionally, it seems there must be less
> complex way to accomplish this task. Thanks.
>
> Note: cin.ignore(INT_MAX, '\n');
> It seemed to me that cin.ignore(INT_MAX); would be more appropriate, but
> it
> is worse.
>
> #include <iostream>
> #include <climits>
> using namespace std;
>
> int main()
> {
> int value = 0;
> cout << "Enter an intergal value: ";
> cin >> value; // Requires 2nd Enter if this line commented out
> cout << "The value was " << value << endl;
>
> int ch;
> cin.ignore(INT_MAX, '\n'); // It seemed that cin.ignore(INT_MAX); would
> be
> while ((ch = cin.peek()) != '\n' && ch != EOF)
> ch = cin.get();
>
> return 0;
> }
I do this in some of my console apps...
#include <conio.h>
int ch= 0;
// Ignore all keys except the Enter key...
while( ch != 0x0d )
{
if ( (ch= getch()) == 0xe0 || ch == 0x00 )
{ // Function key or some other special key was pressed, ignore it...
getch();
}
}
--
============
Frank Hickman
Microsoft MVP
NobleSoft, Inc.
============
Replace the _nosp@m_ with @ to reply.
.
- Follow-Ups:
- Re: Clearing the input buffer - then pausing
- From: Ray Mitchell
- Re: Clearing the input buffer - then pausing
- References:
- Clearing the input buffer - then pausing
- From: Ray Mitchell
- Clearing the input buffer - then pausing
- Prev by Date: RE: Clearing the input buffer - then pausing **PORTABLY**
- Next by Date: Re: How do I examine the keyboard input buffer, or stdin?
- Previous by thread: RE: Clearing the input buffer - then pausing **PORTABLY**
- Next by thread: Re: Clearing the input buffer - then pausing
- Index(es):
Relevant Pages
|