byLine(n)?

helxi via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jun 10 22:36:08 PDT 2017


I was writing a program that reads and prints the first nth lines 
to the stdout:

import std.stdio;

void main(string[] args)
{
     import std.algorithm, std.range;
     import std.conv;
     stdin.byLine.take(args[1].to!ulong).each!writeln;
}

As far as I understand the stdin.byLine.take(args[1].to!ulong) 
part reads all the lines written in stdin.
What if I want to make byLine read only and only first nth line?

stdin.byLine(args[1].to!ulong).each!writeln;

Obviously the code above won't work. Is there any efficient 
workaround?


More information about the Digitalmars-d-learn mailing list