-
map problem
Hello..
Whats wrong with that code:
Code:
map <string, vector <string> > smp;
string n = "somestr";
map <string, vector <string> >::const_iterator v_it;
if ( (v_it = smp.find(n) ) != smp.end() ) {
vector <string> cm = v_it->second; //the critic line
}
Thanks a lot for help
Kind regards
-
Well, in that code, cm no longer exists as soon as the closing brace of the if statement is reached.
A local variable is only in-scope within the braces in which it's declared. You need to pull the declaration outside the if() statement if you want to use cm later.
Your code should compile, but you can't use cm later on.