코딩Coding/Zig_❤️lang_연습
-
Zig연습] Cannot use std.io.getStdOut() inside non-main function코딩Coding/Zig_❤️lang_연습 2022. 8. 9. 21:34
const std = @import("std"); fn output(stream: *std.io.FileOutStream.Stream, s: []const u8) !void { return stream.print("Hello world__Zig\n {}\n", s); } pub fn main() !void { var stdout_file = try std.io.getStdOut(); var stdout_stream = std.io.FileOutStream.init(stdout_file); var stdout = &stdout_stream.stream; try output(stdout, "foo"); } zig run 026_hello2.zig ./026_hello2.zig:8:43: error: expe..
-
zig연습)zig 에러4 마지막에 막힘코딩Coding/Zig_❤️lang_연습 2022. 8. 5. 08:05
const std = @import("std"); const print = std.debug.print; const MyNumberError = error{ TooSmall, TooBig, }; pub fn main() void { var a: u32 = makeJustRight(44) catch 0; var b: u32 = makeJustRight(14) catch 0; var c: u32 = makeJustRight(4) catch 0; print("a={}, b={}, c={}\n", .{ a, b, c }); } fn makeJustRight(n: u32) MyNumberError!u32 { return fixTooBig(n) catch |err| { return err; }; } fn fixTo..