summaryrefslogblamecommitdiff
path: root/example-fileio/file.zig
blob: 41f77394d68bd5c983119667c3b63b2616fa9251 (plain) (tree)






















                                                                                        
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 });
}