Thread: How do I stop cin from crashing my prog

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Back after 2 years Panopticon's Avatar
    Join Date
    Dec 2002
    Posts
    262
    thanks man
    ur da bomb
    I AM WINNER!!!1!111oneoneomne

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    The downside of using the stream states analysis route is that when user inputs 1o1 instead of 101 the fail bit will not be set. Instead the value of 1 will be assigned to the variable. This has two potential problems. First, the user won't know that 1 was assigned to the variable instead of 101 (until some time later, maybe), and second, I believe the o1 will remain in the input buffer to potentially screw up your next input sequence.

    An alternative is to only accept input only as a string and parse the string for appropriateness. True, this isn't foolproof either. It also requires a little more coding on your part, particularly if you want to screen for float/doubles instead of just ints.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why does my prog just stop?
    By Queatrix in forum Windows Programming
    Replies: 4
    Last Post: 03-01-2006, 05:12 PM
  2. BST inser method seems to be crashing my prog
    By ray_broome in forum C++ Programming
    Replies: 12
    Last Post: 04-22-2005, 12:02 PM
  3. why is this prog crashing on delete?
    By Waldo2k2 in forum Windows Programming
    Replies: 2
    Last Post: 12-04-2002, 11:17 PM
  4. Crashing on prog quit
    By Hunter2 in forum Game Programming
    Replies: 11
    Last Post: 09-07-2002, 12:13 PM
  5. sprintf crashing my prog?
    By Eber Kain in forum C++ Programming
    Replies: 11
    Last Post: 11-21-2001, 04:25 AM