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