我的用例:
map<string, Car> cars;
bool exists(const string& name) {
// somehow I should find whether my MAP has a car
// with the name provided
return false;
}
您能否建议用 C++ 实现它的最佳和最优雅的方法?谢谢。
最佳答案
return cars.find(name) != cars.end();
关于c++ - 如何查找std::map中是否存在元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2781899/