std.io
The input/output module. It provides standard output and standard input reading. Whole-file reading and writing, as well as directory and path operations, are covered in std.fs; incremental I/O at the handle level is covered in std.os.
use std.ioPlatform Availability
read_line relies on operating system I/O and is not exported on the wasm32 target. print / println / format_fallback are available on all targets.
Function Overview
| Function | Signature |
|---|---|
print | (...args) -> Void |
println | (...args) -> () |
read_line | () -> String |
format_fallback | (value, type_name: &String) -> String |
Functions
print
print: (...args) -> VoidOutputs all arguments in order, without a trailing newline. Multiple arguments are separated by a single space.
Arguments are formatted as follows: String values output their contents directly; List / Dict / Tuple values are expanded recursively; all other values are output as literals.
main: () -> Void = {
print("hello")
print(" ")
print("world")
println("")
}println
println: (...args) -> ()Behaves like print, but appends a newline to the output.
When called without arguments, println() outputs a blank line:
main: () -> Void = {
println("Hello, YaoXiang!")
}read_line
read_line: () -> StringReads a line from standard input.
Returns: the entire line read, with the trailing newline removed (\n or \r\n). Error: throws E6007 if the read fails.
Interactive examples cannot be run automatically in the documentation. The following is for reference only.
use std.io
main: () -> Void = {
println("请输入你的名字:")
name = io.read_line()
println("你好," + name)
}format_fallback
format_fallback: (value, type_name: &String) -> StringFormats a value according to its type name, producing a prefixed representation such as int(42) / array([1, 2, 3]). Structures are printed by field value (Point(1, 2)), without heap addresses—the address differs on every run, and printing it would make the program's output irreproducible.
This is an internal helper function used by the runtime's generic formatting path callback. In everyday code, use std.convert.to_string directly.
value—— any valuetype_name—— type-name string
Returns: a string representation with a type prefix.
use std.assert
use std.io
use std.string
main: () -> Void = {
s = io.format_fallback(42, "int")
assert(string.contains(s, "42"))
}Related
std.fs—— File, directory, and path operationsstd.os—— File handles and environment variablesstd.convert—— Converting values to strings
