readln() returns new line charater
Jakob Ovrum
jakobovrum at gmail.com
Sat Dec 28 09:42:23 PST 2013
On Saturday, 28 December 2013 at 17:23:30 UTC, Jeroen Bollen
wrote:
> Usually if you're working with a console though the input
> stream won't exhaust and thus the blocking 'readln' would be a
> better option, no?
The blocking behaviour of `stdin` by default is fine. The issue
is that `readln` returns an empty string when `stdin` is
empty/closed, which is different from an empty line (which is
just the line terminator). Approaches that erase the difference
with functions like `chomp` can't tell them apart.
Assuming that `stdin` will never close seems like a bad idea when
it's so easy to handle, and the consequences of it closing can be
harsh (particularly an infinite loop). Even assuming that `stdin`
will never be redirected and always used from a console, an
experienced user might use ^Z to close standard input to signal a
clean end, only to be faced with either an obscure error,
segfault or infinite loop.
More information about the Digitalmars-d
mailing list