eugene.litvinov Posted December 5, 2010 Share Posted December 5, 2010 I use map for save int values with string keys: int listTable[]; idTextTable["key"] = 10; When I want check if value is exists by key "key": if (listTable["key"] != NULL) log.message("listTable[id]: " + listTable["key"]); This is work only if "key" and value 10 added earlier. If I use that: int listTable[]; if (listTable["key"] != NULL) log.message("listTable[id]: " + listTable["key"]); this is cause to error. How I could check if value is exists by key? Thanks Link to comment
michael.zhang Posted December 5, 2010 Share Posted December 5, 2010 int listTable[]; if (listTable.check("key") == 1) log.message("listTable[id]: " + listTable["key"]); The check() method checks for the existence of a key or index. int listTable[]; idTextTable["key"] = NULL; // 0 if (listTable["key"] == NULL) log.message("key maps to NULL(0)"); The [] access operator accesses using key or index, without checking for existence. Checking to see if the accessed location is NULL checks to see if the "key" is mapped to a value of NULL, not whether it exists or not. Hope that helps! :) Link to comment
eugene.litvinov Posted December 6, 2010 Author Share Posted December 6, 2010 Yes, Thanks :) Link to comment
Recommended Posts