我遇到了这段优雅的代码,然而,它依赖于一个模糊但基本的低级特征:
std::string file_path_leaf( std::string const & path )
{
auto const pos = path.find_last_of("/\\"); // windows or posix
return path.substr( pos + 1 ); // a walk on the wild side?
}
Run Code Online (Sandbox Code Playgroud)
在边缘情况下('find_last_of'失败),它正常工作,即它只留下字符串.但它太模糊了吗?