setting istream states question

This is a discussion on setting istream states question within the C++ Programming forums, part of the General Programming Boards category; I've got a problem with setting the state of various istreams in my programming. I'm supposed to input a value ...

  1. #1
    Unregistered
    Guest

    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
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    cin.fail() 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).
    zen

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, 05:22 AM
  3. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 10: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21