How to find whether an element exists in std::map?

后端 未结 11 2162
醉梦人生
醉梦人生 2020-12-07 23:55

My use case:

map cars;
bool exists(const string& name) {
  // somehow I should find whether my MAP has a car
  // with the name provid         


        
11条回答
  •  轮回少年
    2020-12-08 00:46

    This does not answer the question but it might be good to know. You can know if it exists by erasing it.

    bool existed = cars.erase( name );
    

提交回复
热议问题