Reading file by line, weird result

Dfr deflexor at yandex.ru
Fri Dec 27 01:31:21 PST 2013


Hello, here is simple pice of code to read text file into array 
of lines:

import std.stdio;

void main(string args[]) {
     auto file = File(args[1]);
     auto frange = file.byLine();
     char[][] buf;
     foreach (char[] line; frange) {
         buf = buf ~ line;
     }
     writeln(buf);
}

When i run this code for this text file:
--------------cutline-----------
hello
world
of D
and
have a nice day
--------------cutline-----------

then program prints:

["and\n\n", "and\n\n", "and\n", "and", "have a nice day!"]

As you can see, this is complete madness, any idea what is wrong 
here ?



More information about the Digitalmars-d-learn mailing list