c# 写文件时 目录不存在_如何测试C ++中是否存在文件或目录?

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# 写文件时 目录不存在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值