Skip to content

std.io

std.io

std.io is the standard I/O module currently shipped in the repository.

Import

import std.io as io

Reference

NameSignatureDescription
printfunc print(value)write str, bool, i32, i64, or f64 to stdout without newline
printlnfunc println(value)write str, bool, i32, i64, or f64 to stdout with newline
flushfunc flush()flush stdout
read_linefunc read_line() -> strread one line without trailing newline
read_intfunc read_int() -> i32read one i32 token
read_i64func read_i64() -> i64read one i64 token
read_f64func read_f64() -> f64read one f64 token
read_wordfunc read_word() -> strread one whitespace-delimited token
read_allfunc read_all() -> strread the remaining stdin stream
read_intsfunc read_ints(count: i32) -> Array[i32]read count integers
read_i64sfunc read_i64s(count: i32) -> Array[i64]read count 64-bit integers
eprintfunc eprint(value)write str, bool, i32, i64, or f64 to stderr without newline
eprintlnfunc eprintln(value)write str, bool, i32, i64, or f64 to stderr with newline

Examples

import std.io as io
func main():
io.print("hello")
io.println(42)
io.flush()
import std.io as io
import std.string as string
func main():
let name = io.read_word()
io.println(string.concat("hi ", name))
import std.io as io
func sum_items(items: Array[i32]) -> i32:
let total: i32 = 0
for item in items:
total = total + item
return total
func main():
let items = io.read_ints(3)
io.println(sum_items(items))