input range from stdin

via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Sep 18 04:13:34 PDT 2014


On Thursday, 18 September 2014 at 09:21:17 UTC, krzaq wrote:
> That's not what I wanted. Maybe I should explain instead of 
> expecting you to divine my intentions, though :) I am trying to 
> rewrite the following program in D--making it more elegant: 
> http://melpon.org/wandbox/permlink/ff42FoyKgqJK60sm
>
> As you can see, I can have one input line consisting of n words 
> and then n integers and I can read from it easily. My question 
> whether stdin.byLine allows me to do this remains unanswered 
> (or I failed to understand the answer), although I am not 
> hopeful.

You should be able to use `std.algorithm.take` to read exactly 5 
integers. However, in order to read up to the first empty line, 
for example, the input would have to be a forward range (= 
"rewindable"), which stdin.byLine of course is not. Maybe you 
could constructor a wrapper range that caches input lines as 
necessary.


More information about the Digitalmars-d-learn mailing list