I have a vector filled with client class objects sorted by name. The problem starts when I try to get the "highest" name(string class) searched.
A brief example of my problem:
int main()
{
vector<Client> vCli;
vector<Client>::iterator low;
vector<Client>::iterator up;
myClass c1(1, "John Lil", 123);
myClass c2(2, "John Bob", 325);
myClass c3(3, "Alves Hunk", 472);
myClass c4(4, "Gil Diniz", 521);
myClass c5(5, "Boll Yo", 181);
c_Cli.push_back(c1);
c_Cli.push_back(c2);
c_Cli.push_back(c3);
c_Cli.push_back(c4);
c_Cli.push_back(c5);
sort(vCli.begin(), vCli.end(), auxPesqNome[](Cliente a, Cliente b) {return a.name < b.name;} );
/* Correct sort = Alves Hunk, Boll Yo, Gil Diniz,John Bob ,John Lil */
low = lower_bound (vCli.begin(), vCli.end(), "John", [](Cliente a, Cliente b) {return a.name < b.name;});
up = upper_bound (vCli.begin(), vCli.end(), "John", [](Cliente a, Cliente b) {return a.name < b.name;});
cout << (low - vCli.begin()) << endl;
/* Correct output = 3 */
cout << (up - vCli.begin()) << endl;
/* ***INCORRECT output = 3 *** */
return 0
}
I think the problem may be in compound names, but my little experience in c ++ can't solve it.
I would like to replace "lower_bound" and "upper_bound" with "equal_range".