最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c++ - std::filesystem::path in a LinuxPOSIX environment: root_drive vs root_directory vs root_path - Stack Overflow

programmeradmin2浏览0评论

Given an instance of std::filesytem::path in a Linux environment, what exactly do the root_name, root_directory, and root_path methods return?

I understand that in the Linux/POSIX environment, the UNC notation is not used. Therefore, is it true that in the Linux/POSIX environment, root_name has no function or meaning?

Given an instance of std::filesytem::path in a Linux environment, what exactly do the root_name, root_directory, and root_path methods return?

I understand that in the Linux/POSIX environment, the UNC notation is not used. Therefore, is it true that in the Linux/POSIX environment, root_name has no function or meaning?

Share Improve this question edited Mar 16 at 19:08 Remy Lebeau 601k36 gold badges507 silver badges850 bronze badges asked Mar 16 at 18:18 crsguycrsguy 291 silver badge8 bronze badges 5
  • 4 Did you perform any attempt to write a simple program or copy one from cppreference with outputs of results of mentioned functions? – 3CxEZiVlQ Commented Mar 16 at 18:33
  • 1 Currently I don't have access to an up-to-date Linux box. Just writing some code and wanted to make it portable as possible. If I have violated some protocol, I apolofize. I'm not a frequent user here. – crsguy Commented Mar 16 at 20:53
  • Yes, the SO rules were violated, not enough efforts for finding an answer were demonstrated. You don't need access to a linux box. You can use online compiler explorers. Moreover, if you RTM you would realize the "Run this code" button. – 3CxEZiVlQ Commented Mar 16 at 21:29
  • Docker is an option to give yourself updated tooling as well. Or a VM. – sweenish Commented Mar 17 at 11:56
  • Thanks for your patience. I didn't realize you could actually put your own code in the "RTM' window. As an old old fart, I find this new stuff to be quite unimaginable. – crsguy Commented Mar 20 at 16:02
Add a comment  | 

1 Answer 1

Reset to default 3

While cppreference does take a bit of reading to find out what the string would actually be, you can always do a bit of testing yourself:

#include <filesystem>
#include <iostream>

int main()
{
    std::filesystem::path path="/tmp/foo/bar";
    std::cout << "full: "  << path << '\n';
    std::cout << "root name: "  << path.root_name() << '\n';
    std::cout << "root path: "  << path.root_path() << '\n';
    std::cout << "root directory: "  << path.root_directory() << '\n';
}
stieber@gatekeeper:~ $ g++ Test.cpp && ./a.out
full: "/tmp/foo/bar"
root name: ""
root path: "/"
root directory: "/"
发布评论

评论列表(0)

  1. 暂无评论