0Pricing
Zig Academy · Lesson

Reading Files and stdin

Stream input into your program.

Tools Consume Input

A useful CLI usually reads something: a file you name, or text piped into it. Zig gives you clear, explicit ways to do both. 📥

Open a File by Path

Use std.fs.cwd to get the current directory, then openFile to open a path relative to it for reading.

const file = try std.fs.cwd().openFile(path, .{});

All lessons in this course

  1. Reading Command-Line Arguments
  2. Reading Files and stdin
  3. Writing Output and Exit Codes
  4. Package and Release the Binary
← Back to Zig Academy