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

标签 c++ c macos

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

相关文章:

bash - 修复 bash vi 输入模式中的 <right arrow>。不能输入超过最后一个字符

C++ 在类中设置迭代器

C++ 主/工

c - pthreads:以编程方式收集有关在不同状态下花费的时间的信息?

python - 哪个版本的 python 目前最适合 os x?

macos - Brew 医生说 : "Warning:/usr/local/include isn' t writable. “

c++ - 如何生成所有 float ?

c++ - getnameinfo 内存泄漏是否得到确认?

c - 生成关于 'lvalue' 的错误。原因是什么?

C 编程简单指针