我有这段代码
auto path = std::filesystem::path("/root/home/../opt/.");
我尝试了std::filesystem::absolute()
,但后来意识到它不是为了我想要的结果
我的问题是如何将该相对路径转换为绝对路径,以便结果为“/root/opt/”
。
我在Debian g++-9上使用C++17
使用std::filesystem::canonical
将路径转换为绝对路径,并删除所有..
(参考):
auto path = std::filesystem::canonical("/root/home/../opt/.");
给你:
"/root/opt"
也可以使用from这个函数。
std::cout << std::filesystem::path("/root/home/../opt/.").lexically_normal() << std::endl;