Thread: setting istream states question

  1. #1

    Question setting istream states question

    I've got a problem with setting the state of various istreams in my programming. I'm supposed to input a value into a stream and then set the stream state to bad if the value is incorrect. Then I have to clear out the stream and reset it to the good state. Can anybody tell me what functions in the istream class do this? Any help would be appreciated.

  2. #2
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    1,007 to test for the stream state and cin.clear() to set a stream state.

    The default argument for cin.clear() is ios::goodbit which will remove the fail state. If you want to manually fail the stream then you want cin.clear(ios::badbit). However, input of an incorrect type will automatically set ios::badbit (inputing a char where an int is expected).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. istream question
    By lord in forum C++ Programming
    Replies: 8
    Last Post: 11-13-2008, 04:31 PM
  2. Design layer question
    By mdoland in forum C# Programming
    Replies: 0
    Last Post: 10-19-2007, 04:22 AM
  3. Question...
    By TechWins in forum A Brief History of
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  4. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM
  5. istream class
    By bond_007 in forum C++ Programming
    Replies: 0
    Last Post: 01-11-2003, 04:18 PM