c++ - C ++在包含某些字母的字符串向量中查找名称
问题描述
有谁知道在包含某些字母的 C++ 字符串向量中查找名称的好方法?
假设我有一个包含 100 个名称的向量。有没有办法找到例如所有包含“t”字符的名字,比如汤姆、彼得、乔纳森等等?
据我了解,如果我专门搜索“Jonathan”,std::find 只会找到名称 Jonathan。还有另一种可以使用的方法吗?
解决方案
https://en.cppreference.com/w/cpp/algorithm/partition
auto it = std::partition(v.begin(), v.end(), [](std::string s) {
return ( s.find("t") != std::string::npos );
});
推荐阅读
- javascript - 一个关于 -1 和 i 的简单 for 循环问题——
- firebase - 进行firebase身份验证的正确方法是什么
- kubernetes - 使用 K8S 横向扩展
- google-app-engine - 使用 Google App Engine Image API 时有什么方法可以配置平移/裁剪位置?
- swift - 将多个按钮链接到同一个站点 xcode
- react-native - 无法使用 AsyncStorage API 存储登录的用户数据
- azure - 将资源组所有者授予个人和企业帐户
- java - “else if”语句中的逻辑运算符
- java - spring boot-无法读取yaml属性文件application.yml
- android - android/view/View$OnUnhandledKeyEvent 监听器错误