Merge pull request 'added explanation about stdout' (#487) from i481-stdout-explanation into main

Reviewed-on: https://codeberg.org/ziglings/exercises/pulls/487
This commit is contained in:
Chris Boesch
2026-07-01 16:32:38 +02:00
2 changed files with 13 additions and 3 deletions
+8
View File
@@ -30,3 +30,11 @@ pub fn main(init: std.process.Init) !void {
// We just learned of a single statement which can accomplish this. // We just learned of a single statement which can accomplish this.
stdout.print("Hello world!\n", .{}); stdout.print("Hello world!\n", .{});
} }
// Now you must be thinking "Why would I need to do this instead of good
// old 'std.debug.print()'?", but here's what you need to understand:
// 'std.debug.print()' prints its output to stderr, while the stdout_writer
// approach prints to stdout.
// A common practice is to pipe output of a command to other commands,
// and in order for the piping to work, those commands expect thier input
// to come from stdout, not stderr.
+5 -3
View File
@@ -1,9 +1,11 @@
--- exercises/026_hello2.zig 2026-01-09 22:51:45.803358789 +0100 --- exercises/026_hello2.zig 2026-07-01 16:27:18.674459266 +0200
+++ answers/026_hello2.zig 2026-01-09 22:50:46.016166527 +0100 +++ answers/026_hello2.zig 2026-07-01 16:27:08.579220702 +0200
@@ -28,5 +28,5 @@ @@ -28,7 +28,7 @@
// to be able to pass it up as a return value of main(). // to be able to pass it up as a return value of main().
// //
// We just learned of a single statement which can accomplish this. // We just learned of a single statement which can accomplish this.
- stdout.print("Hello world!\n", .{}); - stdout.print("Hello world!\n", .{});
+ try stdout.print("Hello world!\n", .{}); + try stdout.print("Hello world!\n", .{});
} }
// Now you must be thinking "Why would I need to do this instead of good