注册 登录
编程论坛 C++教室

求教 c++关联容器中的问题

qq826647235 发布于 2017-02-22 15:31, 1185 次点击
程序代码:

#include<iostream>
#include<set>
#include<string>

using namespace std;

bool com(const string &a, const string &b)
{
    return a > b;
}

int main()
{
    multiset<string,decltype(com)*> q(com);
    string s;
    while (cin >> s)
    {
        q.insert(s);
    }
    for (auto a : q)
    {
        cout << a << endl;
    }
    getchar();
}


在定义multiset时候不太懂。为什么要用函数初始化q

[此贴子已经被作者于2017-2-22 15:32编辑过]

1 回复
#2
rjsp2017-02-22 16:31
看到“为什么”都头疼,得先猜题主“为什么会问为什么”

你写出 com 函数,不就是给 q 作比较子用的吗?用com初始化q有什么不对?!
1