Please report all spam threads, posts and suspicious members. We receive spam notifications and will take immediate action!
Results 1 to 2 of 2

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




  1. #1
    Join Date
    Feb 2002
    Posts
    125

    Default

    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. #2
    Join Date
    Nov 2001
    Posts
    448

    Default

    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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •