如何在C ++中的元组列表中查找值? [英] How to find a value in a list of tuple in C++?
本文介绍了如何在C ++中的元组列表中查找值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个用c ++编写的元组列表。每个元组由两个元素组成。我想在列表中的元组的第二个元素中找到一个值。我如何找到它?
列表如下:
I have a list of tuple written in c++. each tuple consists of two elements. I want to find a value in the second element of the tuples in the list. how can I find it?
the list is as follow:
list<std::tuple<int, int> > d;
i想要找到d.item [2]中的数字2。
我尝试了什么:
i找到了一些关于在元组列表中查找值的参考资料。但是,那些元组只包含一个元素。但是,我的情况在每个元组中有两个元素。
i want it find for example the number "2" in d.item[2].
What I have tried:
i found some references about finding a value in a list of tuples . but, those tuples had consisted on just one element. but, my case has two elements in each tuple.
推荐答案
检查文档: std :: tuple - cppreference.com [ ^ ]
如果我理解你的话......
所有你需要做的就是循环通过列表 [ ^ ],然后使用std :: get()
函数。
想想吧!
提示:
d(0)
- 返回列表中的第一个元素
std :: get< 1>(d(0))
- 返回列表中第一个元素的元组的第二个元素
Check the documentation: std::tuple - cppreference.com[^]
If i understand you well...
All you need to do is to loop through the elements on the list[^], then to usestd::get()
function.
Think of it!
Tip:
d(0)
- returns the first element on the list
std::get<1>(d(0))
- returns second element of tuple of first element on the list
这篇关于如何在C ++中的元组列表中查找值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文