hello-world #25
Replies: 6 comments 6 replies
-
Hello, world! |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
有文章可以了解 为什么设计成 const std = @import("std"); 这种导入包的方式吗? 而不是 import .. as .. |
Beta Was this translation helpful? Give feedback.
-
没有讲标准输入,给初学者参考哦,其他读取函数在zig 安装目录 lib\std\io.zig文件内,可以看看 var array: [10]u8 = undefined;
const stdout = @import("std").io.getStdOut().writer();
const stdin = @import("std").io.getStdIn().reader();
try stdout.print("Enter a world: ", .{});
const slice: []u8 = array[0..((try stdin.read(&array)) - 2)]; //输入超过8个出问题,哈哈
try stdout.print("{s}\n", .{slice}); |
Beta Was this translation helpful? Give feedback.
-
这里应该说明: zig标准库std.debug.print()函数的实现位于\lib\std\debug.zig,源码如下 /// Print to stderr, unbuffered, and silently returning on failure. Intended
/// for use in "printf debugging." Use `std.log` functions for proper logging.
pub fn print(comptime fmt: []const u8, args: anytype) void {
lockStdErr();
defer unlockStdErr();
const stderr = io.getStdErr().writer();
nosuspend stderr.print(fmt, args) catch return;
} 实际上std.debug.print()的实现还多了同步异步、无缓存等区别,关键词见 https://ziglang.org/documentation/master/ |
Beta Was this translation helpful? Give feedback.
-
在helloworld阶段上mutex,这强度也太高了 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
hello-world
简单、快速地学习 Zig,ziglang中文教程,zig中文教程
https://course.ziglang.cc/hello-world.html
Beta Was this translation helpful? Give feedback.
All reactions