summaryrefslogtreecommitdiff
path: root/example-fileio/file.zig
diff options
context:
space:
mode:
Diffstat (limited to 'example-fileio/file.zig')
-rw-r--r--example-fileio/file.zig23
1 files changed, 23 insertions, 0 deletions
diff --git a/example-fileio/file.zig b/example-fileio/file.zig
new file mode 100644
index 0000000..41f7739
--- /dev/null
+++ b/example-fileio/file.zig
@@ -0,0 +1,23 @@
+const std = @import("std");
+
+const Foo = extern struct {
+ x: u8,
+ y: u8,
+ z: u8,
+};
+
+pub fn main() !void {
+ const f = std.fs.cwd().createFile("moose", .{ .truncate = true }) catch unreachable;
+
+ // Write raw byte slice.
+ try f.writeAll(&[_]u8{ 1, 2, 3, 4 });
+ // Write raw byte slice (ascii chars).
+ try f.writeAll("abcd");
+
+ // Format printing.
+ const w = f.writer();
+ try w.print("{}-{}", .{ 8, 9 });
+
+ // Write struct to file.
+ try w.writeStruct(Foo{ .x = 0xaa, .y = 0xbb, .z = 0xcc });
+}