C / C ++ - Mac OS X - 检查如果文件存在 [英] C/C++ - Mac OS X - Check If file exists
本文介绍了C / C ++ - Mac OS X - 检查如果文件存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果不是使用mac
library< .mach-o / dyld.h>或其他...来创建和写入信息,检查文件是否存在的最好方法是什么?
What is the best way to check if a file exists, if not create it and write info by using mac library <.mach-o/dyld.h> or other..?
推荐答案
您的问题不清楚。
检查文件是否存在是微不足道的 stat()
或 access()
,例如:
Checking if a file exists is trivial - use stat()
or access()
, e.g.:
#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 / code>。找到任何有关C编程的好书,这是任何书中最基本的东西。
Creating a file is similarly trivially - use open()
or fopen()
. Find any good book on C programming, this is the most fundamental thing most any book will teach.
但是< mach-o / dyld.h>
与它有关吗?
这篇关于C / C ++ - Mac OS X - 检查如果文件存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文