linux下使用了C++的stdstring中记录了一个文件的绝对路径加文件名如何获取该文件的路径一行代码
可以使用std::filesystem::path类的parent_path()函数来获取文件的路径。以下是获取文件路径的一行代码示例:
std::filesystem::path filePath = "/path/to/file.txt";
std::string fileDirectory = filePath.parent_path().string();
在上面的示例中,变量filePath记录了文件的绝对路径加文件名。通过调用parent_path()函数,可以获取文件的路径,然后使用string()函数将路径转换为std::string类型。最后将其保存在fileDirectory变量中。
原文地址: http://www.cveoy.top/t/topic/iOcx 著作权归作者所有。请勿转载和采集!