c++ - map.find(var) isn't returning correct value -


sample code :

map<char* , int> map; map["privilege"] = 1;  char* code[]="privilege";  val = map.find(code); // returns map.end() val = map.find("privilege"); // returns correct value 

i need find value in map on basis of variable key :
val = map.find(code);

it returning map.end()

please suggest something

use std::string instead of char * since want save string value, not location. also, wouldn't use name "map" variable (since used)

#include <map> #include <string>  std::map<std::string, int> mymap; mymap["privilege"] = 1;  std::string code = "privilege";  val = mymap.find(code);   val = mymap.find("privilege");   

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -