mirror of
https://codeberg.org/ziglings/exercises.git
synced 2026-02-10 22:24:52 +00:00
exc. 26 migrated
This commit is contained in:
parent
21f86f07ad
commit
b33fd5a744
|
|
@ -5,6 +5,9 @@
|
||||||
//
|
//
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
|
// Instance for input/output, we'll learn how to create them later.
|
||||||
|
const io = std.Options.debug_io;
|
||||||
|
|
||||||
// Take note that this main() definition now returns "!void" rather
|
// Take note that this main() definition now returns "!void" rather
|
||||||
// than just "void". Since there's no specific error type, this means
|
// than just "void". Since there's no specific error type, this means
|
||||||
// that Zig will infer the error type. This is appropriate in the case
|
// that Zig will infer the error type. This is appropriate in the case
|
||||||
|
|
@ -15,17 +18,14 @@ const std = @import("std");
|
||||||
// https://ziglang.org/documentation/master/#Inferred-Error-Sets
|
// https://ziglang.org/documentation/master/#Inferred-Error-Sets
|
||||||
//
|
//
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
// We need an io instance for I/O operations;
|
// We get a Writer interface for Standard Out so we can print() to it.
|
||||||
// we'll learn how to create them later.
|
var stdout_writer = std.Io.File.stdout().writer(io, &.{});
|
||||||
const io = std.Options.debug_io;
|
const stdout = &stdout_writer.interface;
|
||||||
|
|
||||||
// We get a Writer for Standard Out so we can print() to it.
|
|
||||||
var stdout = std.Io.File.stdout().writer(io, &.{});
|
|
||||||
|
|
||||||
// Unlike std.debug.print(), the Standard Out writer can fail
|
// Unlike std.debug.print(), the Standard Out writer can fail
|
||||||
// with an error. We don't care _what_ the error is, we want
|
// with an error. We don't care _what_ the error is, we want
|
||||||
// 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.interface.print("Hello world!\n", .{});
|
stdout.print("Hello world!\n", .{});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
--- exercises/026_hello2.zig 2025-12-27 21:15:21.403899392 +0100
|
--- exercises/026_hello2.zig 2025-12-28 01:51:16.537444980 +0100
|
||||||
+++ answers/026_hello2.zig 2025-12-27 20:28:53.267236800 +0100
|
+++ answers/026_hello2.zig 2025-12-28 01:51:10.280322328 +0100
|
||||||
@@ -27,5 +27,5 @@
|
@@ -27,5 +27,5 @@
|
||||||
// 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.interface.print("Hello world!\n", .{});
|
- stdout.print("Hello world!\n", .{});
|
||||||
+ try stdout.interface.print("Hello world!\n", .{});
|
+ try stdout.print("Hello world!\n", .{});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user