如何在控制台上显示地图内容? [英] How can I display the content of a map on the console?
本文介绍了如何在控制台上显示地图内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个map
声明如下:
map < string , list < string > > mapex ; list< string > li;
如何在控制台上显示以上地图中存储的项目?
How can I display the items stored in the above map 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屋!
查看全文