如果在C++ std :: map中设置了element?

eu.*_*.vl -2 c++ map

如何确定是否设置了std :: map存储中的元素?例:

#include <map>
#include <string>

using namespace std;

map<string, FOO_class> storage;

storage["foo_el"] = FOO_class();
Run Code Online (Sandbox Code Playgroud)

有类似的东西if (storage.isset("foo_el"))吗?

eds*_*ufi 5

试试storage.find("foo_el") != storage.end();.


cpp*_*cpp 5

if (storage.count("foo_el"))
Run Code Online (Sandbox Code Playgroud)

count()返回容器中项目的多次出现,但是每个键只能出现一次.因此storage.count("foo_el"),如果项目存在则为1,否则为0.