The standard input stream.

alias stdin = makeGlobal!(StdFileHandle.stdin)

Return Value

stdin as a File.

Note: The returned File wraps core.stdc.stdio.stdin, and is therefore thread global. Reassigning stdin to a different File must be done in a single-threaded or locked context in order to avoid race conditions.

All reading from stdin automatically locks the file globally, and will cause all other threads calling read to wait until the lock is released.


// Read stdin, sort lines, write to stdout
import std.algorithm.mutation : copy;
import std.algorithm.sorting : sort;
import std.array : array;
import std.typecons : Yes;

void main()
    stdin                       // read from stdin
    .byLineCopy(Yes.keepTerminator) // copying each line
    .array()                    // convert to array of lines
    .sort()                     // sort the lines
    .copy(                      // copy output of .sort to an OutputRange
        stdout.lockingTextWriter()); // the OutputRange