File.readln

Read line from the file handle and return it as a specified type.

This version manages its own read buffer, which means one memory allocation per call. If you are not retaining a reference to the read data, consider the File.readln(buf) version, which may offer better performance as it can reuse its read buffer.

  1. S readln(dchar terminator)
    struct File
    @safe
    S
    readln
    (
    S = string
    )
    (
    dchar terminator = '\n'
    )
  2. size_t readln(C[] buf, dchar terminator)
  3. size_t readln(C[] buf, R terminator)

Parameters

S

Template parameter; the type of the allocated buffer, and the type returned. Defaults to string.

terminator dchar

Line terminator (by default, '\n').

Note: String terminators are not supported due to ambiguity with readln(buf) below.

Return Value

Type: S

The line that was read, including the line terminator character.

Throws

StdioException on I/O error, or UnicodeException on Unicode conversion error.

Examples

// Reads `stdin` and writes it to `stdout`.
import std.stdio;

void main()
{
    string line;
    while ((line = stdin.readln()) !is null)
        write(line);
}

Meta