Announcement

Collapse
No announcement yet.

Visual c++: Is there a flush function for cin?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Visual c++: Is there a flush function for cin?

    Is there a function for cin that will flush it?

    My program is in an endless loop for some reason. I'm in the debugging process. Basically, in a loop structure, the user is asked to enter int numbers and no error checking is done. The user could just as well type in a char value. When they do that's when the loops starts. Let's say I type in "A1". Cin will read the first character to put in int x; only to find it's not an int, so x remains the same and cin sets it state to false. Since this is all inside a loop, the step is repeated, only this time it doesn't stop to ask the user to enter a new int since cin is still in the false state.

  • #2
    It has been awhile since I coded in C++ but I would redeclare the var in the loop or you could do something like this.

    Pseudocode:

    Declare X as integer
    Declare Y as Boolean

    Y=True
    Cout "Please Enter a value in Textbox"
    If x NOT integer then Y=False
    Goto Cout
    Do While Y=True
    PUT YOUR LOOP HERE
    End Do

    Comment

    Working...
    X