![](/img/trans.png)
[英]C++ - Convert from std::filesystem::path to const char
[英]Get the absolute path from std::filesystem::path c++
我有这段代码
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"
您也可以从此 function 使用。
std::cout << std::filesystem::path("/root/home/../opt/.").lexically_normal() << std::endl;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.