-1

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. :)

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
  • 1
    What 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 Answers3

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
0

Thank you all! And myMap[key].first = 0; works. :)

Adronica
  • 1
  • 1