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