以下是Linux C/C++中获取除文件名的所有路径的实现代码:

#include <iostream>
#include <string>
#include <filesystem>

int main() {
    std::string path = "hdfs://192.168.100.1:9000/opt/file_video_orig/C/libRcfDll.so";
    std::filesystem::path fsPath(path);
    
    // Get the parent path
    std::filesystem::path parentPath = fsPath.parent_path();
    
    std::cout << "Parent Path: " << parentPath << std::endl;
    
    // Print each directory in the parent path separately
    for (const auto& directory : parentPath) {
        std::cout << "Directory: " << directory << std::endl;
    }
    
    return 0;
}

该代码使用C++17中的std::filesystem库来操作文件路径。首先,将给定的路径转换为std::filesystem::path对象。然后,使用parent_path()函数获取除文件名的所有路径。最后,使用循环遍历并打印每个目录

linux cc++ 获取除文件名的所有路径 hdfs19216810019000optfile_video_origClibRcfDllso给出实现代码

原文地址: https://www.cveoy.top/t/topic/iwzD 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录