在 C++ 中检查文件是否存在的最佳方法是什么?(跨平台) [英] What’s the best way to check if a file exists in C++? (cross platform)

查看:33
本文介绍了在 C++ 中检查文件是否存在的最佳方法是什么?(跨平台)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读检查 C 中是否存在文件的最佳方法是什么?(跨平台),但我想知道是否有更好的方法使用标准 C++ 库来做到这一点?最好不要尝试打开文件.

I have read the answers for What's the best way to check if a file exists in C? (cross platform), but I'm wondering if there is a better way to do this using standard c++ libs? Preferably without trying to open the file at all.

stataccess 几乎都无法通过 Google 搜索.我应该怎样#include 来使用这些?

Both stat and access are pretty much ungoogleable. What should I #include to use these?

推荐答案

使用 boost::filesystem:

#include <boost/filesystem.hpp>

if ( !boost::filesystem::exists( "myfile.txt" ) )
{
  std::cout << "Can't find my file!" << std::endl;
}

这篇关于在 C++ 中检查文件是否存在的最佳方法是什么?(跨平台)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆