Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

This document has been placed into the public domain by Kris

/*******************************************************************************

        Read a file line-by-line, sending each one to the console. This
        illustrates how to bind a conduit to a text iterator. Iterators
        also support the binding of buffer and string instances.

        Note that iterators are templated for char, wchar and dchar ~ 
        this example uses char

*******************************************************************************/
private import  tango.io.Console,
                tango.io.device.File;

private import  tango.io.stream.Lines;

void main (char[][] args)
{

          if (args.length is 2)
           {
           // open a file for reading
           auto file = new File (args[1]);

           // create a line oriented iterator, and use it to sweep the file
           foreach (line; new Lines!(char) (file))
                    Cout (line).newline;
           }
        else
           Cout ("usage: ")(args[0])(" <filename>").newline;

}