Zeke Xiao

Zeke Xiao

github

Zig Code Snippets

读写文件#

zig version 0.11.0-dev.2837+b55b8e774

const std = @import("std");

pub fn main() !void {
    const value = "hello";

    var my_file = try std.fs.cwd().createFile("file.txt", .{ .read = true });
    defer my_file.close();
    _ = try my_file.write(value);

    var buf: [value.len]u8 = undefined;
    try my_file.seekTo(0);
    const read = try my_file.read(&buf);
    std.debug.print("{s}", .{buf[0..read]});
}
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.