std.file vs

Ali Çehreli acehreli at
Thu Mar 4 12:19:56 PST 2010

Lars T. Kyllingstad wrote:

 > What you're seeing here is actually a consequence of Phobos very much
 > being a work-in-progress.  std.stdio was completely rewritten about a
 > year ago, and it most likely contains what you're looking for.
 >, on the other hand, hasn't seen major updates since 2005 or
 > so, and is most likely an old left-over from D1.  I suspect it will be
 > removed soon, or at least completely rewritten to adhere to the range
 > interface.

I've been using because it uses the generic Stream 
interface like dout and din does.

Using should allow cleaner template code without needing 
'static if' and other conditional compilation features.

 > So, my advice is to use std.stdio.File, and to use it like this:
 >   import std.stdio;
 >   ...
 >   auto file = File(filename);
 >   foreach (line; file.byLine)
 >   {
 >       writeln(line);
 >   }

std.stdio.File has two advantages that I've discovered so far:

- As you also note, it closes the file immediately. With, I have to use 'scope' objects

- It allows chosing text vs. binary file I/O mode. always converts the newline character 
according to the system


More information about the Digitalmars-d-learn mailing list