检查文件是否存在的最佳方法是什么,如果不存在则使用 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/