我有一个元组 vector vector<tuple<int,int>> vector;
我想修改它包含的一个元组。
for (std::tuple<int, int> tup : std::vector)
{
if (get<0>(tup) == k)
{
/* change get<1>(tup) to a new value
* and have that change shown in the vector
*/
}
}
我不确定如何更改元组的值并将更改反射(reflect)在 vector 中。我试过使用
get<1>(tup) = v;
但这不会改变 vector 中元组的值。我怎样才能做到这一点?谢谢。
最佳答案
通过引用捕获元组
:
for (tuple<int, int> &tup : vector){
// ^here
if (get<0>(tup) == k){
get<1>(tup) = v;
}
}
关于c++ - 修改元组 vector 中的元组 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28874317/