Looked around SO and couldn’t find quite what I needed. I am looking for a way to pull the key from the outside map and the value from the inside map for usin in an output statement. If I had one map I know I can pull the data I need from the inside map by using insideMap[key]. However, the [] operator does not seem to work in this implementation ((*itr).second)[keyword].
map< string, map<string, int> >::const_iterator itr;
for( itr=books.begin(); itr!=books.end(); ++itr)
//code I need here
The problem with
[]isconst-ness of your iterator: the[]operator is notconst, so you need to usefind(keyword)instead, and dereference the iterator that it returns:You could also switch to non-const iterator and use
[].