0

検索された名前の最初の位置と最後の位置を取得したいと思います。

同様の命令が実行されているのを見たことがありますが、このコードをコンパイルできません。lower_bound と upper_bound でエラーが発生します。

C++11 でコンパイル

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

class Client
{
public:
    int id;
    string name;
    int number;
};

int main()
{
    vector<Client>::iterator low;
    vector<Client>::iterator up;
    string s_name;

    Client c1;
    c1.id = 1;
    c1.name = "jhon";
    c1.number = 123;

    Client c2;
    c2.id = 2;
    c2.name = "Mart";
    c2.number = 987;

    Client c3;
    c3.id = 3;
    c3.name = "Jhon";
    c3.number = 256;

    Client c4;
    c4.id = 4;
    c4.name = "Anna";
    c4.number = 851;

    vector<Client> vCli{c1, c2, c3, c4};

    sort(vCli.begin(), vCli.end(), [](Client a, Client b) { return a.name < b.name; });

    s_name = "Jhon";

    low = lower_bound(vCli.begin(), vCli.end(), s_name, [](Client a, Client b) { return a.name < b.name; });
    up = upper_bound(vCli.begin(), vCli.end(), s_name, [](Client a, Client b) { return a.name < b.name; });

    cout << (low - vCli.begin()) << endl;
    cout << (up - vCli.begin()) << endl;

    return 0;
}
C:\Program Files (x86)\CodeBlocks\MinGW\lib\gcc\mingw32\5.1.0\include\c++\bits\predefined_ops.h|144|
error: no match for call to '(main()::<lambda(Client, Client)>) (Client&, const std::__cxx11::basic_string<char>&)'|
4

3 に答える 3