如何更改列表中元组的值? [英] How to change the value of tuple in a list?
本文介绍了如何更改列表中元组的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好。我想更新列表的元组中的值。列表中的元组包含图形的顶点和每个顶点的度数。我使用igraph库来处理图形。我写了以下代码。但是,列表d中元组的值没有改变(我用粗线表示我的意思)。我该如何解决这个问题呢?
hello. I want to update values in tuples of a list. the tuples in the list contains vertices of a graph and the degree of each vertices. I used igraph library to work on the graph. I wrote the following code. but, the value of tuple in the list d is not changed (I bolded the line that I mean). how can I resolve the problem?
std::list<std::tuple<int, int> >::iterator it;
list<std::tuple<int, int> > d;
it = d.begin();
for (int i=0;i<igraph_vcount(&graph);i++)
{
tuple<int, int> f1= it._Ptr[0]._Myval;
std::get<1>(f1) = static_cast<int>( VECTOR(v)[i]);
std::advance(it,1);
}
我尝试过:
我使用visual studio 2012.
What I have tried:
I use visual studio 2012.
推荐答案
据我所知,元组是不可变的。这意味着您无法在创建后更改它。
您可以使用数组而不是元组。
请参阅:
< tuple> - C ++参考a> [ ^ ]
As far as i remember a tuple is immutable. This means that you cannot change it after creation.
You can use array instead of tuple.
See:
<tuple> - C++ Reference[^]
更改元组中值的唯一方法是使用旧元组中的值和要更改的元素创建一个新元组并返回该元组。
The only way to change a value in a tuple is to make a new tuple with the values from the old tuple and the one you want to change and return that.
这篇关于如何更改列表中元组的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文