liveBook · Manning

I/O

As explained in Systems Programming with Zig

Input/output is the transfer of data between a program and external devices, files, networks, or other processes.

I/O transfers data between a program and external resources. In Zig, std.Io provides an interface for file I/O, buffering, asynchrony, and concurrency while leaving programmers in control of buffering and its memory. section 1.6.2

Listing 1.2 All your codebase still belong to us
const std = @import("std");

pub fn main(init: std.process.Init) !void { #1
    const io = init.io;

    const stdout = std.Io.File.stdout(); #2
    var stdout_buffer: [1024]u8 = undefined;
    var stdout_writer = stdout.writer(io, &stdout_buffer); #3
    const writer = &stdout_writer.interface; #3

    try writer.print("All your codebase still belong to us!\n", .{}); #4
    try writer.flush(); #5
}

A small Zig program writes a greeting to standard output through a buffered writer, then explicitly flushes it. section 1.6.2

How Systems Programming with Zig covers it

How deep it goes
Traces writer setup, buffered printing, and flushing; mentions io_uring without implementing it.
Examples
Prints a greeting to standard output with a buffered writer and explicit flush.
What you can do after
Apply std.Io to write and flush output through a buffered writer.
How it connects
Relates I/O to file I/O, buffering, flushing, asynchrony, and concurrency.

Also explained in

Compare how 6 books explain I/O →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Systems Programming with Zig. The section links point to the parts of the book it draws on.