How to update std::map after using the find method?

后端 未结 6 1343
自闭症患者
自闭症患者 2020-12-12 12:11

How to update the value of a key in std::map after using the find method?

I have a map and iterator declaration like this:

         


        
6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-12 12:51

    You can use std::map::at member function, it returns a reference to the mapped value of the element identified with key k.

    std::map mymap = {
                                   { 'a', 0 },
                                   { 'b', 0 },
                               };
    
      mymap.at('a') = 10;
      mymap.at('b') = 20;
    

提交回复
热议问题