c++ - 检查路径是否包含 C++ 中的另一个
问题描述
我正在寻求实现类似的目标
if (basePath.contains(subPath)) { // subPath 是 basePath 的一个 subPath }
我知道我可以通过遍历's 的父母,在途中subPath
检查来实现这一点。basePath
有std
办法吗?
std::filesystem::path("/a/b/").contains("/a/b/c/d") == true
解决方案
您可以遍历两个路径中的项目:
for (auto b = basePath.begin(), s = subPath.begin(); b != basePath.end(); ++b, ++s)
{
if (s == subPath.end() || *s != *b)
{
return false;
}
}
return true;
推荐阅读
- angular - 安装 Angular 的问题
- asp.net - 清除未使用的 iis 网站
- git - 使用 git 合并手动复制目录中的更改
- excel - 没有VBA或Form的Excel单元格中的双列DropList / ComboBox?
- swift - 放大或缩小时如何缩放 SKNode?
- mongodb - Connection to MongoDB ReplicaSet on Kubernetes
- android - Android 模拟器虚拟麦克风在 macOS 上不起作用
- php - 无法使用燃料 kotlin 向我的 PHP 页面发送 POST 请求
- javascript - Javascript:只能从输入中获取 nodeValue() 而不是 value()?
- ruby-on-rails - 公寓宝石的固定装置