comment

Action executed in 0.000

infinite loop answer

After a little research i found this web page.

  • If std::cin is presented with input it cannot process, std::cin goes into a "fail" state
  • The input it cannot process is left on the input stream.

So "asdf" is not valid integer input. It is left on the input stream. Next time we read, same thing occurs.

What's the best resolution? After cin >> Command we can check the fail flag in cin with this if (!cin) { cin.clear(); cin.ignore( numeric_limits<streamsize>::max(), '\n' ); } then reprompt.

parent post: code snippet
notify me: yes

Comments

none yet

Post a Comment

* indicates a required field
anonymous (If you want to identify yourself, please sign in first.)
required This field is required.

Max size is 2 MB, aspect ratio 3:4 width:height
required This field is required.
Please include a short description.
required This field is required.

480 characters remaining.
is public

(Use this field if you have to. 3000 characters remaining.)
1 quarter, 2 pennies, 2 dimes + 100

Trackback URL

http://derocher.org/~brian//trackback.php?ParentId=1241

form