gpt4 book ai didi

c++ - 如何确定 2 个路径是否引用可移植 C++ 中的同一个文件

转载 作者:行者123 更新时间:2023-11-30 04:40:24 25 4
gpt4 key购买 nike

我想知道是否有一种可移植方法来确定 2 个不同的路径是否实际上引用了同一个文件。

我已阅读 this thread但特定于 Windows。

据我所知,fstream 不适合这份工作。

最佳答案

文件系统库

从 C++17 开始,您可以使用标准 <filesystem> 图书馆。您要找的函数是equivalent , 在命名空间 std::filesystem 下:

bool std::filesystem::equivalent(const std::filesystem::path& p1, const filesystem::path& p2 );

总结自documentation : 该函数以两条路径为参数,返回true如果它们引用相同的文件或目录,false否则。还有一个noexcept采用第三个参数的重载:std::error_code在其中保存任何可能的错误。

有关更多信息,请查看 my answerthread you mentioned 上.

关于c++ - 如何确定 2 个路径是否引用可移植 C++ 中的同一个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1443206/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com