使用std::find搜索对的向量时忽略其中一个值
Ignoring one of the value when searching the vector of pairs using std::find
在给定的成对向量中
static std::vector<std::pair<int,int>> v
当我使用std::find 搜索矢量时,如何忽略其中一个值
std::find(v.begin(), v.end(), std::make_pair(first int, /*ignored value*/)) - v.begin();
使用更好的算法:std::find_if
:
auto it = std::find_if(v.begin(), v.end(), [first](const std::pair<int, int>& elem){
return elem.first == first;
});
或者find
与范围-v3:的不同风味
auto it = ranges::find(v,
first, // the value
&std::pair<int, int>::first // the projection
);
相关文章:
- 如何在不知道对应关系的情况下在字符串中搜索字符并将其分配给另一个字符?
- 这是一个二叉搜索树吗?黑客排名问题
- 如果你有一个固定大小的数组,你需要遍历它!n次,使用二进制搜索如何改变时间复杂性
- 在结构向量中搜索一个数据成员,然后打印匹配的所有数据成员
- Rcpp ,在文件中搜索一个值
- 从另一个向量中搜索和找到元素的有效方法
- 将一个不充实的二进制搜索树转换为完整的二进制搜索树
- 如何在 中输入记录的一个字段时搜索记录
- 如何编写一个 void 函数,该函数将在数组中搜索值,并通过引用将该值的位置传递回 main 函数
- C 搜索数组以获取一个数字,但如果找不到该数组,则不会触发其他语句
- 通过搜索下一个字符来出乎意料的行为
- 从C++二进制搜索树中删除一个节点(类而非结构)
- 哪种数据结构是在一个向量中搜索和计数对象对的最佳数据结构
- 为什么我的原始二叉搜索树被修改,即使我在另一个节点中复制了根节点
- 从文件搜索搜索单词,然后将整个行复制到另一个文件
- 在Java中使用一个或更多单词搜索整个数据库
- 在C++中为二叉搜索树创建一个删除函数
- C++,我想在字符串中搜索一个字符,并输出包含该字符的所有单词
- 很难从我的二进制搜索树中删除一个节点
- 如何在这个c++程序中创建一个搜索函数