c++ - Get the key and values of map elements in a vector of maps from a constant iterator to the vector of maps -
i have vector of maps containing strings .,i.e,
vector< map <string,string> > vectorofmaps; vector< map <string,string> >::const_iterator itr =vectorofmaps.begin();
vectorofmaps filled in function , caller function can access const_iterator itr.
how access key , respective value of each map element in vectorofmaps?
any help appreciated:)
edit: got solution.
map<string,string> mymap = (*itrvectorofmaps); while(loop till end element) { for(map<string,string>::iterator itm = mymap.begin(); itm != mymap.end(); itm++) { cout<<"key="<<itm->first<<" => value="<<itm->second<<endl; } itrvectorofmaps++; mymap=(*itrvectorofmaps); }
you can utilize first
, second
keywords access map
elements you're iterating on vector
of map
s.
for(auto const& currentmap : vectorofmaps) // loop on maps { for(auto const& element : currentmap) // loop on elements of current map { std::string const& key = element.first; std::string const& value = element.second; } }
c++ stl stdvector stdmap
No comments:
Post a Comment