c++ - Cocos2D X: How to check if a key exists for a plist file? -


I am using the following code to read data from my game plist:

  int LevelNum = SOME_VALUE_FROM_OUTSIDE; Manmap mapfile = filesutils :: meet () - & gt; GetValueMapFromFile ("LevelDetails.plist"); Std :: string strLevel = std :: to_string (levelNum); Valuemap Map Level = Mapfile (Stellwell) .asValueMap ();  

LevelDetails.plist is a plist with the dictionary as root. The problem is that there may be occasions where no name is levelNum / strLevel. So I have to check that the key exists before I run this line:

map map = mapFile.at (strLevel) .asValueMap (); // Sometimes

If the exception is thrown, what is the proper way to check if a key named levelNum / strLevel is present or not?

Because ValueMap is a std :: unordered_map, you can use methods of that class:

  if (mapFile.count (strLevel) .count ()> gt; {Manmap Maps = mapfile.tr (strLevel) .asValueMap (); }  

The Valmax announcement in Cocos 2D X is:

  typedef std :: unordered_map & lt; Std :: string, value & gt; ValueMap;  

Comments

Popular posts from this blog

winforms - C# Form - Property Change -

javascript - amcharts makechart not working -

java - Algorithm negotiation fail SSH in Jenkins -