M
Mike Copeland
I have the following application stub that compiles and works. Now I
wish to add "find" functionality (based on matching the "baseBib"
element), and I can't see from the documentation or examples I've found
hoe to do so. The STL set "find" seems meant only for scalar objects
(but the optional insert parameter supports field-based ordering...).
What am I missing in this? TIA
#pragma warning (disable:4786)
#include <set>
#include <iostream>
#include <string>
using namespace std;
class Entrant
{
public:
int baseBib;
char baseEvent;
};
class LoToHigh
{
public:
bool operator()(Entrant s1, Entrant s2)
{
if(s1.baseBib < s2.baseBib) return true;
else return false;
}
};
int main(int argc, char* argv[])
{
set <Entrant, LoToHigh> myEntrant;
set <Entrant, LoToHigh>::iterator it;
Entrant a1, a2, a3;
a1.baseBib = 2077, a1.baseEvent = 'a';
a2.baseBib = 2066, a2.baseEvent = 'b';
a3.baseBib = 2055, a3.baseEvent = 'a';
myEntrant.insert(a1), myEntrant.insert(a2);
myEntrant.insert(a1), myEntrant.insert(a3);
cout << "The # of Entrants is " << myEntrant.size() << endl;
for(it = myEntrant.begin(); it != myEntrant.end(); it++)
{
cout << it->baseBib << "\t" << it->baseEvent << endl;
}
return 0;
}
wish to add "find" functionality (based on matching the "baseBib"
element), and I can't see from the documentation or examples I've found
hoe to do so. The STL set "find" seems meant only for scalar objects
(but the optional insert parameter supports field-based ordering...).
What am I missing in this? TIA
#pragma warning (disable:4786)
#include <set>
#include <iostream>
#include <string>
using namespace std;
class Entrant
{
public:
int baseBib;
char baseEvent;
};
class LoToHigh
{
public:
bool operator()(Entrant s1, Entrant s2)
{
if(s1.baseBib < s2.baseBib) return true;
else return false;
}
};
int main(int argc, char* argv[])
{
set <Entrant, LoToHigh> myEntrant;
set <Entrant, LoToHigh>::iterator it;
Entrant a1, a2, a3;
a1.baseBib = 2077, a1.baseEvent = 'a';
a2.baseBib = 2066, a2.baseEvent = 'b';
a3.baseBib = 2055, a3.baseEvent = 'a';
myEntrant.insert(a1), myEntrant.insert(a2);
myEntrant.insert(a1), myEntrant.insert(a3);
cout << "The # of Entrants is " << myEntrant.size() << endl;
for(it = myEntrant.begin(); it != myEntrant.end(); it++)
{
cout << it->baseBib << "\t" << it->baseEvent << endl;
}
return 0;
}