小编Joe*_*eMo的帖子

我应该修复这个不起眼但优雅的c ++代码片段吗?

我遇到了这段优雅的代码,然而,它依赖于一个模糊但基本的低级特征:

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'失败),它正常工作,即它只留下字符串.但它太模糊了吗?

c++ language-lawyer

7
推荐指数
1
解决办法
339
查看次数

标签 统计

c++ ×1

language-lawyer ×1