I am overloading the input stream operator for use with a Time class and would like to manually set the failbit of the input stream if the input doesn't match my expected time format (hh:mm). Can this be done? How?
Thanks!
I am overloading the input stream operator for use with a Time class and would like to manually set the failbit of the input stream if the input doesn't match my expected time format (hh:mm). Can this be done? How?
Thanks!
Yes, you can set it with
ios::setstate
, like so:The second output will not be produced because
cout
is in the failed state.(An exception seems cleaner to me, but YMMV)