如何更改设置元素? [英] How to change a set element?

查看:64
本文介绍了如何更改设置元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更改 set 中的元素,所以我使用了 set< T> :: iterator 。但是,编译器认为元素是const。然后我意识到 set< T> :: iterator const_iterator ...

I want to change the element in a set, so I used set<T>::iterator. However, the compiler argues "the element is const". Then I realized that set<T>::iterator is a const_iterator...

那么,如何更改元素?删除它,然后插入一个新的吗?

So, how I can change the element? Erase it and then insert a new one?

推荐答案

集中的元素将按排序顺序。如果允许您修改元素,则无法保持此排序顺序。因此,您不能修改该项目。您需要删除现有元素并插入一个新元素。

The elements of the set will be in sorted order. If you are allowed to modify an element, then this sorting order can not be maintained. Hence you can not modify the item. You need to erase the existing element and insert a new one.

这篇关于如何更改设置元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆