DLang Notes and Examples
← prev | next →     Top-level ToC     /stdin-stdout-stderr.html     (printable version)

1 Stdout

write("hi", "there", "bye")  // prints "hitherebye" to stdout
writeln()  // with a newline

writef()   // like printf
writefln() // like printf, with a newline

All of those are buffered, though they flush when a newline is printed.

writefln("%s, %s, %s", "won", "too", "tree"); // "won, too, tree"

2 Stdin

import std.stdio : writeln, stdin;
import std.string : strip;
import std.algorithm : splitter;

void main() {
    foreach (line; stdin.byLine()) {
        foreach (word; splitter(strip(line))) {
            writeln(word);
        }
    }
}