<分区>
我遇到了这段优雅的代码,然而,它依赖于一个晦涩但基本的低级特征:
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?
}
在极端情况下('find_last_of' 失败)它工作正常,即它单独留下字符串。但它是不是太晦涩了?