Boost文件系统weakly_canonical无法解析没有父文件夹的相对路径

问题描述 投票:0回答:1

我想获得绝对规范的路径,给定在Windows和Linux中都可以使用的boost文件系统的相对路径。我希望它也可以用于不存在的路径。

我正在使用boost.1.60以来可用的weakly_canonical(path relativePath),以完成此操作。但它的行为不符合预期(至少在Windows中)。

<

因此,最后,我被迫先调用绝对值,然后再调用weakly_canonical以使其正常工作。

请参见两个案例的摘要。

#include <string> #include <iostream> #include <boost/filesystem.hpp> using boost::filesystem; path relativePath("foo"); path canonical_path = weakly_canonical(relativePath); path abs_canonical_path = weakly_canonical(absolute(relativePath)); std::cout << "Using weakly_canonical: " << canonical_path.string() << std::endl; std::cout << "Using weakly_canonical and absolute: " << abs_canonical_path.string() << std::endl;

例如,如果current_path是“ C:\ path \ to \ some \ folder”,则说明:

    relativePath =“ ./foo”
  • Using weakly_canonical: C:\path\to\some\folder\foo Using weakly_canonical and absolute: C:\path\to\some\folder\foo
      relativePath =“ ../ foo”
  • Using weakly_canonical: C:\path\to\some\foo Using weakly_canonical and absolute: C:\path\to\some\foo
      relativePath =“ foo”
  • Using weakly_canonical: foo Using weakly_canonical and absolute: C:\path\to\some\folder\foo
    这最后一种情况使我感到困惑,因为我希望weakly_canonical也可以优先使用当前工作目录。

    一起使用绝对和weakly_canonical是否正确?还是我在滥用“ weakly_canonical?”

    我想获得绝对规范的路径,给定在Windows和Linux中都可以使用的boost文件系统的相对路径。我希望它也可以用于不存在的路径。我正在使用...

  • c++ boost-filesystem
    1个回答
    0
    投票
    嗯,documentation说“

    返回符号链接已解析且结果归一化的p

    © www.soinside.com 2019 - 2024. All rights reserved.