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

后端 未结 11 2154
醉梦人生
醉梦人生 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:43

    Sure, use an iterator

    map::const_iterator it = cars.find(name);
    return it!=cars.end();
    

提交回复
热议问题