Discussion:
istream
(too old to reply)
Kevin
2005-04-14 23:17:42 UTC
Permalink
Just to make sure I have implemented right the istream:


1)
input = "abckda3434klj-" should create the number "3434" and set flag for
fail bit istream = "abckdaklj-"
or
since we read a non-integer just set the fail bit and exit: istream =
"abckda3434klj-"

2)
input = "a-kdfjk34kj45" should create the number "-3445" and set fail bit
istream = "akdfjkkj"
or
again, just set the fail bit and exit: istream ="a-kdfjk34kj45"

3)
input = "abcdefghijk" should set fail bit
number = 0
or
number not modified
Jeff Ford
2005-04-15 14:12:29 UTC
Permalink
Post by Kevin
1)
input = "abckda3434klj-" should create the number "3434" and set flag for
fail bit istream = "abckdaklj-"
or
since we read a non-integer just set the fail bit and exit: istream =
"abckda3434klj-"
The second one. If the first character isn't - or a digit, don't modify
the istream and set the fail bit. Same answer for #2 and #3.

Jeff
--
Jeff Ford http://www.cs.utexas.edu/users/jeffford/
Kevin
2005-04-16 02:50:42 UTC
Permalink
One other possibility
input = "3245klhj34" is this:
number = 324534 istream = klhj
or
number = 3245 istream = klhj34
Post by Kevin
1)
input = "abckda3434klj-" should create the number "3434" and set flag for
fail bit istream = "abckdaklj-"
or
since we read a non-integer just set the fail bit and exit: istream =
"abckda3434klj-"
2)
input = "a-kdfjk34kj45" should create the number "-3445" and set fail bit
istream = "akdfjkkj"
or
again, just set the fail bit and exit: istream ="a-kdfjk34kj45"
3)
input = "abcdefghijk" should set fail bit
number = 0
or
number not modified
Jeff Ford
2005-04-17 02:21:18 UTC
Permalink
Post by Kevin
One other possibility
This one's correct.
Post by Kevin
number = 3245 istream = klhj34
Please erase the parts of old posts that you are not commenting on when
you post a followup.

Jeff
--
Jeff Ford http://www.cs.utexas.edu/users/jeffford/
David Grohmann
2005-04-18 23:51:12 UTC
Permalink
what should we do when istream = -a123

fail or bad on second character? (i think bad for both of these because
by the time you realize that the stream is no good, you have taken off 2
characters and cant put both back on to it.)

______________

David Grohmann
David Grohmann
2005-04-19 01:50:14 UTC
Permalink
I guess making use of peek() you can deal with a 2 character deep error.
and still put the stream back together.



______________

David Grohmann
Post by David Grohmann
what should we do when istream = -a123
fail or bad on second character? (i think bad for both of these because
by the time you realize that the stream is no good, you have taken off 2
characters and cant put both back on to it.)
______________
David Grohmann
Jeff Ford
2005-04-19 13:55:17 UTC
Permalink
Post by David Grohmann
what should we do when istream = -a123
I won't check for this since it's the only two character deep error. If
you want to deal with it, you could either consume the '-' and set the
stream to bad, look ahead with peek(), or treat it as the number 0.

Jeff
--
Jeff Ford http://www.cs.utexas.edu/users/jeffford/
Loading...