On Thursday, 6 September 2018 at 16:13:42 UTC, hridyansh thakur wrote:
how to read a file line by line in D

std.stdio.File.byLine()

Refer the doc here: https://dlang.org/library/std/stdio/file.by_line.html

An example from the doc:

```
import std.algorithm, std.stdio, std.string;
// Count words in a file using ranges.
void main()
{
    auto file = File("file.txt"); // Open for reading
    const wordCount = file.byLine()            // Read lines
                          .map!split           // Split into words
.map!(a => a.length) // Count words per line
                          .sum();              // Total word count
    writeln(wordCount);
}
```
  • file io hridyansh thakur via Digitalmars-d-learn
    • Re: file io Arun Chandrasekaran via Digitalmars-d-learn
      • Re: file io rikki cattermole via Digitalmars-d-learn
        • Re: file io Steven Schveighoffer via Digitalmars-d-learn
          • Re: file io Steven Schveighoffer via Digitalmars-d-learn

Reply via email to