boost::filesystem get relative path

后端 未结 5 2128
予麋鹿
予麋鹿 2020-12-29 20:20

What methods of the boost::filesystem library can help me to get a path relative to another path?

I have a path /home/user1/Downloads/Books

5条回答
  •  温柔的废话
    2020-12-29 20:52

    In new versions of boost (starting in 1.60), you can use boost::filesystem::relative. (See the documentation here.)

    #include 
    #include 
    namespace fs = boost::filesystem;
    
    int main()
    {
        fs::path parentPath("/home/user1/");
        fs::path childPath("/home/user1/Downloads/Books");
        fs::path relativePath = fs::relative(childPath, parentPath);
        std::cout << relativePath << std::endl;
    }
    

提交回复
热议问题