Tuesday 15 February 2011

dictionary - C++ Loop through Map -



dictionary - C++ Loop through Map -

i want loop through each element in map , count string , int component on line.

what have far:

void output(map<string, int> table) { map<string, int>::iterator it; (it = table.begin(); != table.end(); it++) { //how access each element without knowing of string-int values? } }

you can accomplish next :

map<string, int>::iterator it; ( = symboltable.begin(); != symboltable.end(); it++ ) { std::cout << it->first // string (key) << ':' << it->second // string's value << std::endl ; }

with c++11 ( , onwards ),

for (auto const& x : symboltable) { std::cout << x.first // string (key) << ':' << x.second // string's value << std::endl ; }

c++ dictionary

No comments:

Post a Comment