cin.peek problem

Hi,

say I am using stringstream to get three inputs in a line, and I want to check if the first two inputs are integer. (the last input can be anything).
I use stringstream.fail(), and if it's not integer, it will fail.
I try the following inputs cases:

4 3 r // ok

r 3 r // not ok; first one is not integer

4 r t // not ok; second one is not integer
4 3r t // shouldn't be ok, because the second input is not integer

the case where 4 3r t shouldn't be ok because it fails the requirment, but the stringstream turns out treating 3r as two separate inputs: 3 is the second input, and r is the third input. The question is: how can I do to make it detect 3r as the invalid second input, instead of treating 3r as two inputs.

Thanks
I am not sure why you are trying to bend the usual rules for this one case. You have three inputs on the line: "4", "3", and "r", two integers followed by anything else. According to your description, this satisfies your requirement.
Last edited on
Topic archived. No new replies allowed.