parent_path() with or without trailing slash

后端 未结 4 854
北海茫月
北海茫月 2020-12-19 02:56

As explained in the documentation, the expected output of the following is:

boost::filesystem::path filePath1 = \"/home/user/\";
cout << filePath1.pare         


        
4条回答
  •  无人及你
    2020-12-19 03:42

    You can use std::filesystem::canonical with C++17:

    namespace fs = std::filesystem;
    
    fs::path tmp = "c:\\temp\\";
    
    tmp = fs::canonical(tmp); // will remove slash
    
    fs::path dir_name = tmp.filename(); // will get temp
    

提交回复
热议问题