Hello world/Newbie: Difference between revisions

add explanation for regular writing to stdout
(explain when to use Zig debug.print)
(add explanation for regular writing to stdout)
Line 2,914:
 
===Using standard streams===
 
<lang zig>
// Save the file as `hello_world.zig`
// Run the program using the command - `zig run hello_world.zig`
 
const std = @import("std");
 
pub fn main() !void {
const stdout = std.io.getStdOut().outStream();
// `try` is a shorthand for `fn_call() catch |err| return err;`.
try stdout.print("Hello, {}\n", .{"world"});
// See also documentation for `catch`, `defer` and `errdefer`
// for code flow adjustments
try stdout.printwriter().writeAll("Hello, {}world!\n", .{"world"});
}
</lang>
37

edits