我有一段代码
auto path = std::filesystem::path("/root/home/../opt/.");我试过std::filesystem::absolute(),但后来意识到这不是为了我想要的理由
我的问题是如何将相对路径转换为绝对路径,从而使推理成为"/root/opt/"。
我在Debian g++-9上使用c++17。
发布于 2020-07-04 11:52:09
使用std::filesystem::canonical将路径转换为删除了所有.. (参考文献)的绝对路径:
auto path = std::filesystem::canonical("/root/home/../opt/.");给你:
"/root/opt"发布于 2020-07-04 12:00:31
您也可以使用此函数。
std::cout << std::filesystem::path("/root/home/../opt/.").lexically_normal() << std::endl;https://stackoverflow.com/questions/62728674
复制相似问题