gpt4 book ai didi

c++ - C/C++ - Mac OS X - 检查文件是否存在

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:47:56 25 4
gpt4 key购买 nike

检查文件是否存在的最佳方法是什么,如果不存在则使用 mac 创建它并写入信息图书馆 <.mach-o/dyld.h> 或其他..?

最佳答案

你的问题不清楚。

检查文件是否存在很简单 - 使用 stat()access() ,例如:

#include <unistd.h>

int res = access(path, R_OK);
if (res < 0) {
if (errno == ENOENT) {
// file does not exist
} else if (errno == EACCES) {
// file exists but is not readable
} else {
// uh oh
}
}

创建文件同样简单 - 使用 open()fopen() .查找有关 C 编程的任何好书,这是大多数书都会教授的最基本的内容。

但是有什么<mach-o/dyld.h>有关系吗?

关于c++ - C/C++ - Mac OS X - 检查文件是否存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8580606/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com