RosettaCodeData/Task/Input-loop/D/input-loop-1.d

24 lines
668 B
D
Raw Permalink Normal View History

2015-02-20 00:35:01 -05:00
void main() {
import std.stdio;
2013-04-10 21:29:02 -07:00
2015-02-20 00:35:01 -05:00
immutable fileName = "input_loop1.d";
foreach (const line; fileName.File.byLine) {
pragma(msg, typeof(line)); // Prints: const(char[])
// line is a transient slice, so if you need to
// retain it for later use, you have to .dup or .idup it.
line.writeln; // Do something with each line.
}
// Keeping the line terminators:
foreach (const line; fileName.File.byLine(KeepTerminator.yes)) {
// line is a transient slice.
line.writeln;
}
foreach (const string line; fileName.File.lines) {
// line is a transient slice.
line.writeln;
2013-04-10 21:29:02 -07:00
}
}