c# 写文件时 目录不存在
How to test a path (a file or directory exists) in C++?
如何在C ++中测试路径(文件或目录存在)?
In Bash, the [ -f ]
and [ -d ]
tests can test whether a file or a directory exist. What are the corresponding C++ ways for these tests?
在Bash中, [ -f ]
和[ -d ]
测试可以测试文件或目录是否存在。 这些测试对应的C ++方法是什么?
To test whether a file or dir (a path) exists, you may call stat()
against the path and check its return value.
要测试文件或目录(路径)是否存在,可以针对路径调用stat()
并检查其返回值。
#include <sys/stat.h>
bool IsPathExist(const std::string &s)
{
struct stat buffer;
return (stat (s.c_str(), &buffer) == 0);
}
翻译自: https://www.systutorials.com/how-to-test-a-file-or-directory-exists-in-c/
c# 写文件时 目录不存在