找不到(STL)的对库



我正在使用迭代器编写一个C++程序。我有一个数据结构,它是一张地图。我使用迭代器从映射的开头到结尾进行循环,对于映射的每个元素,我都对键和值执行一些操作。

因此,当我想知道映射中特定元素的键和值时,我会在迭代器上使用first()second()

喜欢这个:

#include <map>
#include <pair>
map<unsigned long, int> myMap;
map<unsigned long, int>::const_iterator it;
for(it = myMap.cbegin(); it != myMap.cend(); ++it)
{
    unsigned long key_of_map = it.first();
    int val = it.second();
    cout << "Key is : " << key_of_map << endl << "Value is : " << val << endl;
}

当我编译它时,它告诉我:

"../src/myfile.cpp:16:10:致命错误:找不到"配对"文件"

我正在使用Eclipse(版本Luna),这是我从官方网站下载的标准版本(我没有更改任何内容)。

你需要

 #include <utility>

使用std::pair<>

最新更新