module watt.io.std

Standard streams and simple utility functions.

The global declaration of the watt.io.streams that map onto the operating system's standard output, input, and error.

There are also some simple functions declared here. These are the default writeln and friends you use when you import watt.io. The writing functions output to standard output, and the reading functions read from standard input.

Example

// This:
writeln("Hello, world.");
// ...is equivalent to this:
output.writeln("Hello, world.");

Code Map

//! Standard streams and simple utility functions.
module watt.io.std;


//! An OutputFileStream that outputs to stdout.
global output: OutputFileStream;
//! An OutputFileStream that outputs to stderr.
global error: OutputFileStream;
//! An InputFileStream that reads from stdin.
global input: InputFileStream;

//! Write s to output.
fn write(s: const(char)[]) { }
//! Write s to output, then write a newline character.
fn writeln(s: const(char)[]) { }
//! Write the string representation of an i32 to output.
fn writeln(i: i32) { }
//! Write the string representation of a size_t to output.
fn writeln(i: size_t) { }
//! Write the string representation of a bool to output.
fn writeln(b: bool) { }
//! Write a newline to output.
fn writeln() { }
//! Format a string and write it to output.
fn writef(s: const(char)[]) { }
//! Format a string, write it to output, then output a newline.
fn writefln(s: const(char)[]) { }
//! Read text from input.
fn readln() string { }
global output: OutputFileStream

An OutputFileStream that outputs to stdout.

This will appear on the console/terminal, if the application was launched from one.

global error: OutputFileStream

An OutputFileStream that outputs to stderr.

Like output, this will appear on the console, but is used for errors, and can be redirected separately to output.

global input: InputFileStream

An InputFileStream that reads from stdin.

This will either read from the user's keyboard, or from a file redirected to stdin by the user.

fn write(s: const(char)[])

Write s to output.

Same as output.write(s).

Parameters

s

An array of characters to be written to output.

fn writeln(s: const(char)[])

Write s to output, then write a newline character.

Same as output.writeln(s).

Parameters

s

An array of characters to be written to output, before a newline.

fn writeln(i: i32)

Write the string representation of an i32 to output.

Same as output.writefln("%s", i).

Parameters

i

An i32 to write to output.

fn writeln(i: size_t)

Write the string representation of a size_t to output.

Same as output.writefln("%s", i).

Parameters

i

A size_t to write to output.

fn writeln(b: bool)

Write the string representation of a bool to output.

Same as output.writefln("%s", b).

Parameters

b

A bool to write to output.

fn writeln()

Write a newline to output.

Same as output.writeln("").

fn writef(s: const(char)[])

Format a string and write it to output.

See watt.text.format for format string documentation.
Same as output.writef(s, ...).

Parameters

s

The format string.

fn writefln(s: const(char)[])

Format a string, write it to output, then output a newline.

See watt.text.format for format string documentation.
Same as output.writefln(s, ...).

Parameters

s

The format string.

fn readln() string

Read text from input.

Blocks until the enter key has been pressed, and the text entered is returned. The newline character is not included in the returned string.

Same as input.readln().

Return

The text that was input on input, not including the newline.