Visual c++ 显示地图的内容
我如何显示这个称为索引的地图的内容Visual c++ 显示地图的内容,visual-c++,Visual C++,我如何显示这个称为索引的地图的内容 map< string, vector< pair<string, int> > > index map索引 我创建了一个迭代器,并在映射的开头使用以下代码创建它: map< string, vector< pair<string, int> > >::iterator it; it = index.begin(); map
map< string, vector< pair<string, int> > > index
map>索引
我创建了一个迭代器,并在映射的开头使用以下代码创建它:
map< string, vector< pair<string, int> > >::iterator it;
it = index.begin();
map::迭代器;
it=index.begin();
…我使用这个for循环来显示地图内容,但它给了我错误:
for ( it =index.begin() ; it != index.end(); it++ )
cout << (*it).first <<(*it).second <<endl;
for(it=index.begin();it!=index.end();it++)
cout(*it)。第二个在这个上下文中本身没有意义。您需要使用vector公共接口从中提取数据(请参见vector
文档中的内容),或者执行您需要的任何操作。而不是映射
// the type of the data being stored:
typedef pair<string, int> data_t;
// an overload for that:
ostream &operator<<(ostream &os, data_t> const &d) {
return os << d.first << d.second;
}
ostream &operator<<(ostream &os, pair<string, data_t> const &d) {
return os << d.first << d.second;
}
copy(index.begin(), index.end(), ostream_iterator<data_t>(cout, "\n"));