billfor
June 18th, 2002, 02:52 PM
I need to learn how to use the find method to search for a value in a set. But specifically,..... I need to search for an object that has a member variable with a particular value. For example I have
a sample set below. I am inserting name, social security number and other information. I need to search for an object in the set that has a particular social security number. How do I do this?
typedef std::set< MGenPName, std::less< MGenPName> > MGenPNameSet;
typedef std::set< MGenPName, std::less< MGenPName> >::iterator MGenPNameSetIter;
class MGenPName : private Terms // Class name
{
public: //ctor - dtor
MGenPName(){;} ;
// Accessor
const CString& DName();
const CString& DSynID();
const int iSSNumber();
void SetiSSNumber(int);
.
.
}
//
void main(void)
{
MGenPName FirstOject;
FirstObject.SetiSSNumber(3446668889);
MGenPNameSet m_GpnTpnSet; // Collection
// The set is loaded with MGenPname objects
.
.
.
// Now I want to search through the set: m_GpnTpnSet for the matching
// Social security number. How do I do this ???
//
MGenPNameSetIter mIter = m_GpnTpnSet.begin();
mIter.find( ???????); // I want to iterate through the
// 3446668889 list until I find the
//social security number
}
a sample set below. I am inserting name, social security number and other information. I need to search for an object in the set that has a particular social security number. How do I do this?
typedef std::set< MGenPName, std::less< MGenPName> > MGenPNameSet;
typedef std::set< MGenPName, std::less< MGenPName> >::iterator MGenPNameSetIter;
class MGenPName : private Terms // Class name
{
public: //ctor - dtor
MGenPName(){;} ;
// Accessor
const CString& DName();
const CString& DSynID();
const int iSSNumber();
void SetiSSNumber(int);
.
.
}
//
void main(void)
{
MGenPName FirstOject;
FirstObject.SetiSSNumber(3446668889);
MGenPNameSet m_GpnTpnSet; // Collection
// The set is loaded with MGenPname objects
.
.
.
// Now I want to search through the set: m_GpnTpnSet for the matching
// Social security number. How do I do this ???
//
MGenPNameSetIter mIter = m_GpnTpnSet.begin();
mIter.find( ???????); // I want to iterate through the
// 3446668889 list until I find the
//social security number
}