Memory limit and infinite loop.

Pages: 12
Garbage is garbage. If you operate with garbage you get undefined behaviour
Undefined behaviour is undefined. So it may work...

The runs are independent. If the read is successful, it's successful (cin remains valid).

The solution seems to be the use of cin.clear() before every cin statement?
No. You are saying 'there was an error, but it doesn't matter, lets keep going'.
Besides if you only clear it, the buffer remains the same, so you will try to read that faulty input (that's what the ignore is for)

Some programs expects that the input ends with EOF.
¿How they check that? They just keep going as far as they can (until the streams gets invalidated) while(cin>>word)
Clearing the stream will make harder to know when to finish.

There are alternatives. One is to read a line, and then convert that to the variable that you want.
I kind of hate that yo-yo code.

Also don't assume that there is a human user. It can be another program or a file the one that is giving you input.
Topic archived. No new replies allowed.
Pages: 12