如何显示地图内容? [英] How to display map contents?
本文介绍了如何显示地图内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一张地图
map< string, string> > mapex;列表< string> li;
如何在控制台上显示上述地图项目。
<$ p $ p>
typedef map< string,list< string>> :: const_iterator MapIterator;
for(MapIterator iter = mapex.begin(); iter!= mapex.end(); iter ++)
{
cout< Key:<< iter-> first<< endl<< Values:< endl;
typedef list< string> :: const_iterator ListIterator;
for(ListIterator list_iter = iter-> second.begin(); list_iter!= iter-> second.end(); list_iter ++)
cout< < * list_iter<< endl;
}
I have a map
map < string , list < string > > mapex ; list< string > li;
how to display the above map items on the console.
解决方案
Well it depends on how you want to display them, but you can always iterate them easily:
typedef map<string, list<string>>::const_iterator MapIterator;
for (MapIterator iter = mapex.begin(); iter != mapex.end(); iter++)
{
cout << "Key: " << iter->first << endl << "Values:" << endl;
typedef list<string>::const_iterator ListIterator;
for (ListIterator list_iter = iter->second.begin(); list_iter != iter->second.end(); list_iter++)
cout << " " << *list_iter << endl;
}
这篇关于如何显示地图内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文