有多种方法可以检查文件是否存在。
我知道的选项是:
boost::filesystem exists()
access()
stat()
ifstream is_open()
有谁知道其中哪一个提供了最高的性能?
编辑:假设在访问时间不是一个因素的 /dev/shm 上运行。
有多种方法可以检查文件是否存在。
我知道的选项是:
boost::filesystem exists()
access()
stat()
ifstream is_open()
有谁知道其中哪一个提供了最高的性能?
编辑:假设在访问时间不是一个因素的 /dev/shm 上运行。
这里的运行时将由切换到内核模式和文件系统驱动程序的操作主导——甚至忽略磁盘时间。它们中的任何一个都不太可能提供卓越的性能。最好选择提供最佳界面的那个 - boost::filesystem
.
现代 C++ | 更新
C++17 提供了这个标准函数:
#include <filesystem>
int main()
{
std::filesystem::path FullPath("C:\\Test.txt");
bool bExists = std::filesystem::exists(FullPath);
}