Kla*_*aus 4 c++ c++17 std-filesystem
如果我使用像absolute()我总是得到一个包含引号的路径的函数.
文件系统函数中是否有一种方法可以删除此引号,使其能够与std :: ifstream一起使用?
fs::path p2 { "./test/hallo.txt" };
std::cout << "absolte to file : " << fs::absolute(p2) << std::endl;
Run Code Online (Sandbox Code Playgroud)
收益:
Run Code Online (Sandbox Code Playgroud)"/home/bla/blub/./test/hallo.txt"
我需要
Run Code Online (Sandbox Code Playgroud)/home/bla/blub/./test/hallo.txt
代替.
手动执行它没有问题,但我想询问文件系统库中是否有方法.
std::operator << (std::filesystem::path const &) 具体如下:
在路径p上执行流输入或输出.
std::quoted用于在以后由流输入操作符读取时空格不截断[sic].
所以这是流式传输路径时的预期行为.你需要的是path::string():
返回本机路径名格式的内部路径名,转换为特定的字符串类型.
std::cout << "absolte to file : " << absolute(p2).string() << std::endl;
// ^^^^^^^^^
Run Code Online (Sandbox Code Playgroud)
我也删除了,fs::因为absolute可以通过ADL找到.