std::io

std::io

Printing to standard output and standard error.

Contents

NameSummary
printlnWrites s followed by a newline to standard output.
printWrites s to standard output without a trailing newline.
eprintlnWrites s followed by a newline to standard error.
eprintWrites s to standard error without a trailing newline.
flushFlushes the C runtime's stdio buffers on every stream.

println

fn println(const s: string)

Writes s followed by a newline to standard output.

Unbuffered: the bytes are out when the call returns. A line shorter than 4096 bytes goes out in a single write(2), so concurrent lines from different threads are not split. Longer lines take two writes (the text, then the newline). Write errors are ignored.

Parameters

  • s: the text to write

Example

import std::io

fn main() -> i32 {
    io::println("hello")
    return 0
}

print

fn print(const s: string)

Writes s to standard output without a trailing newline.

Unbuffered, like println. Write errors are ignored.

Parameters

  • s: the text to write

eprintln

fn eprintln(const s: string)

Writes s followed by a newline to standard error.

Same single-write behaviour as println. Because neither stream is buffered, output to stdout and stderr interleaves in call order when both go to the same place (2>&1).

Parameters

  • s: the text to write

eprint

fn eprint(const s: string)

Writes s to standard error without a trailing newline.

Parameters

  • s: the text to write

flush

fn flush()

Flushes the C runtime's stdio buffers on every stream.

Nothing in std::io buffers, so this exists only for ordering against C and C++ code that writes through stdio (printf, fwrite(stdout), a C++ library). stdout is block-buffered when it is a pipe or a file, so bytes such code wrote before a print here can otherwise appear after it. Call flush at that boundary.

Generated from Kairo source, Apache-2.0 WITH AdditionRef-Kairo-Runtime-exception.