,c++,c++17,std-filesystem"/>

首页 > 解决方案 > 为什么 path::root_name() 有不同的行为

问题描述

在过去的几天里,我一直在尝试一些函数filesystemexperimental/filesystem库的行为。

注意:我在https://godbolt.org/上运行了代码

下面是带有输出的代码片段

1. 实验/文件系统

#include <iostream>
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;

int main()
{
auto  p = fs::path("//net");
std::cout<<"p = " << p
         <<"\np.root_name= "<< p.root_name()
         <<"\nand p.root_Dir= "<< p.root_directory()
         <<"\np.is_absolute= "<<p.is_absolute()<<std::endl;
}

输出:

p = "//net"    
p.root_name= "//net"    
and p.root_Dir= ""    
p.is_absolute= 0

在此处输入图像描述 2. 文件系统

#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
 
int main()
{
auto  p = fs::path("//net");
std::cout<<"p = " << p
         <<"\np.root_name= "<< p.root_name()
         <<"\nand p.root_Dir= "<< p.root_directory()
         <<"\np.is_absolute= "<<p.is_absolute()<<std::endl;
}

输出:

p = "//net"
p.root_name= ""
and p.root_Dir= "/"
p.is_absolute= 1

有没有办法研究这些功能的实现?

在此处输入图像描述

标签: c++c++17std-filesystem

解决方案


推荐阅读