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

问题描述

我试图使用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”的成员

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

解决方法

std::map没有名为first的成员函数。您是说std::pairvalue_type的{​​{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