Character type for each line, defaulting to immutable char.
Use Yes.keepTerminator to include the terminator at the end of each line.
Line separator ('\n' by default). Use std.ascii.newline for portability (unless the file was opened in text mode).
import std.algorithm, std.array, std.stdio; // Print sorted lines of a file. void main() { auto sortedLines = File("file.txt") // Open for reading .byLineCopy() // Read persistent lines .array() // into an array .sort(); // then sort them foreach (line; sortedLines) writeln(line); }
Returns an input range set up to read from the file handle one line at a time. Each line will be newly allocated. front will cache its value to allow repeated calls without unnecessary allocations.
Note: Due to caching byLineCopy can be more memory-efficient than File.byLine.map!idup.
The element type for the range will be Char[]. Range primitives may throw StdioException on I/O error.