026_hello2.zig 903 B

1234567891011121314151617181920212223
  1. //
  2. // Great news! Now we know enough to understand a "real" Hello World
  3. // program in Zig - one that uses the system Standard Out resource...which
  4. // can fail!
  5. //
  6. const std = @import("std");
  7. // Take note that this main() definition now returns "!void" rather
  8. // than just "void". Since there's no specific error type, this means
  9. // that Zig will infer the error type. This is appropriate in the case
  10. // of main(), but can have consequences elsewhere.
  11. pub fn main() !void {
  12. // We get a Writer for Standard Out so we can print() to it.
  13. const stdout = std.io.getStdOut().writer();
  14. // Unlike std.debug.print(), the Standard Out writer can fail
  15. // with an error. We don't care _what_ the error is, we want
  16. // to be able to pass it up as a return value of main().
  17. //
  18. // We just learned of a single statement which can accomplish this.
  19. stdout.print("Hello world!\n", .{});
  20. }