Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i replace element in set?

Tags:

c++

set

I want to replace an element in a set.After searching in Google, I came across this function replace, but when I used it, it gave me an error

no member named 'replace' in

What are other ways of updating or replacing an element in set?

like image 468
sasasasa Avatar asked May 27 '17 06:05

sasasasa


People also ask

Can we change element in set?

Set elements are constant and may not be modified in place.

How do I change an element in a set Python?

Modifying a set in Python We cannot access or change an element of a set using indexing or slicing. Set data type does not support it. We can add a single element using the add() method, and multiple elements using the update() method. The update() method can take tuples, lists, strings or other sets as its argument.

Can we modify set in C++?

The value itself can identify each element in a set, i.e., they act as keys themselves. We can insert elements in or remove elements from a set in C++ but cannot modify them since the values become constant once stored in the set.

How do you find the set element?

The standard solution to check for existence of an element in the set container ( std::set or std::unordered_set ) is to use its member function find() . If the specified element is found, an iterator to the element is returned; otherwise, an iterator to the end of the container is returned.


1 Answers

You have got to erase() one element and insert() the new one. replace is not defined for std::set. See http://www.cplusplus.com/reference/set/set/

like image 91
Gerriet Avatar answered Oct 06 '22 04:10

Gerriet