Zeke Xiao

Zeke Xiao

github

Zig 代码片段

读写文件#

zig 版本 0.11.0-dev.2837+b55b8e774

const std = @import("std");

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

    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]});
}
加载中...
此文章数据所有权由区块链加密技术和智能合约保障仅归创作者所有。