一行代码获取C++ std::string中的文件路径 (不使用std库函数)
可以使用std::string的find_last_of()函数和substr()函数来实现。
std::string filePath = '/path/to/file.txt';
std::string fileDirectory = filePath.substr(0, filePath.find_last_of('/'));
这行代码会将文件路径中最后一个斜杠(/)之前的部分提取出来,即文件的路径。
原文地址: https://www.cveoy.top/t/topic/qupx 著作权归作者所有。请勿转载和采集!