132
|
1
|
|
2 private import tango.io.Console,
|
|
3 tango.io.FileConduit;
|
|
4
|
|
5 private import tango.text.stream.LineIterator;
|
|
6
|
|
7 /*******************************************************************************
|
|
8
|
|
9 Read a file line-by-line, sending each one to the console. This
|
|
10 illustrates how to bind a conduit to a stream iterator (iterators
|
|
11 also support the binding of a buffer). Note that stream iterators
|
|
12 are templated for char, wchar and dchar types.
|
|
13
|
|
14 *******************************************************************************/
|
|
15
|
|
16 void main (char[][] args)
|
|
17 {
|
|
18 if (args.length is 2)
|
|
19 {
|
|
20 // open a file for reading
|
|
21 scope file = new FileConduit (args[1]);
|
|
22
|
|
23 // process file one line at a time
|
|
24 foreach (line; new LineIterator!(char)(file))
|
|
25 Cout (line).newline;
|
|
26 }
|
|
27 else
|
|
28 Cout ("usage: lineio filename").newline;
|
|
29 } |