如何在C++中使用map函数

如何在C++中使用map函数,c++,C++,在这段代码中,当使用count搜索结构变量k时,我得到了这个错误 #include<iostream> #include<algorithm> #include<cstdio> #include<map> #include<vector> using namespace std; struct cno{ int sub[5]; }; int main() { int n; map<cno,int> s

在这段代码中,当使用count搜索结构变量k时,我得到了这个错误

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<map>
#include<vector>
using namespace std;
struct cno{
    int sub[5];
};
int main()
{
    int n;
    map<cno,int> s;
    int maxN = -1;
    struct cno k;
    while(scanf("%d",&n) && n){
        for(int i = 0;i<5;i++){
            cin>>k.sub[i];
        }
        if(!s.count(k)){   //Error in this line.
            s[k] = 1;
            maxN = max(maxN,1);
        }
        else{
            int m = s[k] + 1;
            s[k] = m;
            maxN = max(maxN,m);
        }
    }
    return 0;   
}

C++中如何使用计数函数?计数函数返回什么值?< /p> 一个STD::MAP要求它的键类型实现。在普通语言中,您必须能够使用std::map所需的键类型实现来比较键。用通俗易懂的语言,你必须能够使用比较键,地图才能工作,必须有操作员地图才能工作,必须有操作员??谢谢你的回答Armen。你能解释一下我怎么写比较器函数吗。我需要按照struct变量的升序对元素进行排序。谢谢Armen的回答。你能解释一下我怎么写比较器函数吗。我需要按照struct变量的升序对元素进行排序。

‘const cno’ is not derived from ‘const std::reverse_iterator<_Iterator>’
       { return __x < __y; }
struct cno a, b;

if (a < b)
  // ...
map<K, V, Cmp>