| ... | @@ -70,10 +70,14 @@ | ... | @@ -70,10 +70,14 @@ |
| 70 | <li><a href="#mersenne">Mersenne Twister Random Number Generator</a></li> | 70 | <li><a href="#mersenne">Mersenne Twister Random Number Generator</a></li> |
| 71 | </ul> | 71 | </ul> |
| 72 | <h3 id="hello">Hello World</h3> | 72 | <h3 id="hello">Hello World</h3> |
| 73 | <pre><code class="zig">const io = @import("std").io; | 73 | <pre><code class="zig">const std = @import("std"); |
| 74 | | 74 | |
| 75 | pub fn main() -&gt; %void { | 75 | pub fn main() -&gt; %void { |
| 76 | %return io.stdout.printf("Hello, world!\n"); | 76 | // If this program is run without stdout attached, exit with an error. |
| | 77 | var stdout_file = %return std.io.getStdOut(); |
| | 78 | // If this program encounters pipe failure when printing to stdout, exit |
| | 79 | // with an error. |
| | 80 | %return stdout_file.write("Hello, world!\n"); |
| 77 | }</code></pre> | 81 | }</code></pre> |
| 78 | <p>Build this with:</p> | 82 | <p>Build this with:</p> |
| 79 | <pre>zig build-exe hello.zig</pre> | 83 | <pre>zig build-exe hello.zig</pre> |