错误:“ class std :: map”没有名为“ first”的成员

时间:2020-10-17 08:53:00

标签: c++ dictionary unordered-map

我试图使用map来计算数组中所有元素的频率。这是我正在尝试的代码-

void count(int arr[] , int n){
    map<int ,int> d;
    for(int i=0;i<n ;i++){
        d[arr[i]]++;
    }
    for(auto i : d){
       cout<<d.first<<" "<<d.second<<"\n";
    }
}

基本上,我使用map来存储数组元素的频率,并在C ++ 14上进行了尝试,但是它给出了以下错误: 错误:“ class std :: map”没有名为“ first”的成员

我认为地图中内置了第一和第二个成员,那么为什么会给出错误? 如果代码中有任何更正,请告诉我

2 个答案:

答案 0 :(得分:1)

std::map没有名为first的成员函数。您是说std::pairvalue_type的{​​{1}}并提供对键值对的访问吗?

答案 1 :(得分:1)

class c { int? id; } methods: { selesai() { let vm = this; vm.spinner = true; axios .post( ipBackend + "/admin/create", { createNewUser: this.formInput }, { headers: { accesstoken: localStorage.getItem("token"), }, } ) .then(function (response) { console.log(response) vm.spinner = false; this.$router.push({ path: "/profilkonselor" }); }) .catch((err) => {}); }, 字段位于地图的元素(属于first类型)中,而不在地图本身中。

second
相关问题