An initial value assumption about map in c++

前端 未结 1 847
借酒劲吻你
借酒劲吻你 2021-01-12 11:09

I am initializing a map map ex; in C++. I could not find contains_key or similar function in stl, hence I am just using ex[inputString]+

相关标签:
1条回答
  • 2021-01-12 11:25

    Yes, values that do not exist when accessed with operator[] are default-constructed. For numeric values, this is 0.

    That said, you're looking for the count method:

    bool hasElement = ex.count("element");
    
    0 讨论(0)
提交回复
热议问题