Updated Zig Hello World program
The current Zig version is 0.15.1, which includes breaking changes. For example, the Hello World! program from an older blog post no longer works!
$ zig run /tmp/hw.zig
/tmp/hw.zig:4:15: error: root source file struct 'Io' has no member named 'getStdOut'
try std.io.getStdOut().writer().print("Hello, World!\n", .{});
~~~~~~^~~~~~~~~~
/opt/homebrew/Cellar/zig/0.15.1/lib/zig/std/Io.zig:1:1: note: struct declared here
const builtin = @import("builtin");
Here is an updated version:
const std = @import("std");
pub fn main() !void {
const stdout_file = std.fs.File.stdout();
try stdout_file.writeAll("Hello World!\n");
}
And here is an alternative version that prints to standard error:
const std = @import("std");
pub fn main() void {
std.debug.print("Hello {s}!\n", .{"World"});
}
Both produce the expected output in Zig 0.15.1.