zaterdag 16 juni 2007

EOF ends INPUT

When a cin method detects the EOF, is sets a flag in the cin object, indicating the EOF condition. When this flag is set, cin does NOT read anymore input, and further calls to cin have NO effect. For file input, this makes sense because you shouldn't read past the end of a file.
For keyboard input, however, you might use a simulated EOF ()to terminate a loop but then want to read more input later.
The cin.clear() method clears the EOF flag and lets input proceed again.
Keep in mind, however, that in some systems, typing Ctrl-A effectively terminates both input and output beyond the powers of cin.clear() to restore them.

Geen opmerkingen: