检查C ++中是否存在文件的最好方法是什么? (跨平台) [英] What’s the best way to check if a file exists in C++? (cross platform)
本文介绍了检查C ++中是否存在文件的最好方法是什么? (跨平台)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已阅读什么是最好的方法来检查一个文件是否存在于C? (跨平台),但我想知道是否有更好的方法来使用标准的c + + libs?最好不要试图打开文件。
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.
stat
和访问
几乎无法访问。
Both stat
and access
are pretty much ungoogleable. What should I #include
to use these?
推荐答案
使用 boost ::文件系统:
#include <boost/filesystem.hpp>
if ( !boost::filesystem::exists( "myfile.txt" ) )
{
std::cout << "Can't find my file!" << std::endl;
}
这篇关于检查C ++中是否存在文件的最好方法是什么? (跨平台)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文