C++如何获取文件路径的父路径和文件名?
// Returns the path-string without the filename part
std::string getFolderPath(const std::string &path) {
const size_t found = path.find_last_of("/\\");
return (found == std::string::npos) ? path : path.substr(0, found);
}
// Returns only the filename part (after the last slash)
std::string getFileName(const std::string & path) {
const size_t found = path.find_last_of("/\\");
return (found == std::string::npos) ? path : path.substr(found+1);
}