"Hello, World!"

Hi, Im new to Zig and programming in general (although I was fooling around in Godot).
Im trying the language for the first time out of curiosity.
I try to write ”Hello, World!”:

const std = @import("std");

pub fn main() void{

std.debug.print("Hello, {s}!\n",.{"World"});

}

but I have an error show up when I run the program:

[Running] zig run "~/hello.zig"

hello.zig:3:49: error: expected ',' after argument

    std.debug.print("Hello, {s}!\n", .{"World"});

                                                ^

I wrote it in Code - OSS
Zig version: 0.16.0

1 Like

Nevermind, I saved the project with this exact script and then ran it.

[Running] zig run "~/hello.zig"

Hello, World!

Seems like the last one I wrote wasnt working correctly. I will keep in mind that I have to save the script first.

Hi @Jakus. Welcome to Ziggit! I think we’ve all forgotten to save the file from time to time :slight_smile:

One thing that may help you is setting up your editor to format your code when you save. It could be built in, or you could use the zls LSP. It’s absolutely not required, but I personally like the feedback of hitting save and seeing my code adjust into the usual shape. It makes me want to save.

3 Likes