Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual c++ 显示地图的内容_Visual C++ - Fatal编程技术网

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"));