I would like to ask if there is a way how to change a value in map<pair<int, int>, pair<int, int>> myMap
? Thank you. :)
Asked
Active
Viewed 220 times
-1

Adronica
- 1
- 1
-
Possible duplicate of [Replace a key in a std::map](https://stackoverflow.com/questions/25620178/replace-a-key-in-a-stdmap) – eesiraed Oct 10 '19 at 21:20
-
1What is the problem you have? What have you tried so far and how it didin't work? – Yksisarvinen Oct 10 '19 at 21:23
-
Possible duplicate of [What is the fastest way to change a key of an element inside std::map](https://stackoverflow.com/questions/5743545/what-is-the-fastest-way-to-change-a-key-of-an-element-inside-stdmap) – Michiel Leegwater Oct 10 '19 at 21:50
3 Answers
2
Depending on what you want to specifically change in your std::pair
value (I assume you know which 'key'
you want to refer):
To change the first sub-value of the value:
myMap[key].first = 0; //or whatever int value you need
To change the second sub-value:
myMap[key].second = 0; //or whatever int value you need
To change the whole value (replace it with a new pair):
myMap[key] = std::make_pair(0, 0); //or whatever int values you need

bloody
- 1,131
- 11
- 17
1
It's very simple as long as you have a key.
pair<int, int> key = <some key>;
myMap[key] = <some new value>;

R Sahu
- 204,454
- 14
- 159
- 270