Difference between map[] and map.at in C++?

前端 未结 2 1132
日久生厌
日久生厌 2020-12-31 00:21

What is the difference in getting a value through aMap[key] and aMap.at(key) in C++?

2条回答
  •  粉色の甜心
    2020-12-31 01:15

    In C++11 map::at exists (who knew?).

    It throws an exception if the key doesn't exist, find returns aMap.end() if the element doesn't exist, and operator[] value-initializes a new value for the corresponding key if no value exists there.

提交回复
热议问题