我正在使用 MFC,并且我有这个课程:
class CUnit
{
private:
CString name;
CString init;
CString chp;
CString rhp;
CString condition;
public:
CUnit(void);
~CUnit(void);
void setName( CString str );
void setInit( CString str );
void setCHP( CString str );
void setRHP( CString str );
void setCond( CString str );
CString getName() const;
CString getInit() const;
CString getCHP() const;
CString getRHP() const;
CString getCond() const;
bool operator< ( CUnit ) const;
};
CUnit::CUnit(void)
{
}
CUnit::~CUnit(void)
{
}
bool CUnit::operator< ( CUnit unit ) const
{
return !( this->init < unit.init );
}
void CUnit::setName( CString str )
{
name = str;
}
void CUnit::setInit( CString str )
{
init = str;
}
void CUnit::setCHP( CString str )
{
chp = str;
}
void CUnit::setRHP( CString str )
{
rhp = str;
}
void CUnit::setCond( CString str )
{
condition = str;
}
CString CUnit::getName() const
{
return name;
}
CString CUnit::getInit() const
{
return init;
}
CString CUnit::getCHP() const
{
return chp;
}
CString CUnit::getRHP() const
{
return rhp;
}
CString CUnit::getCond() const
{
return condition;
}
我成功地从 Editboxes 中获取了值,但是当我将它们插入 a 时,set<CUnit>
当我取回CString
值时,我只得到第一个字母。我尝试了一个向量,但它都是一样的。
我像这样填充集合:
vector<CUnit> units;
CUnit unit;
CEdit *edit;
CString str;
edit = reinterpret_cast<CEdit *>(GetDlgItem(IDC_NAME1));
edit->GetWindowText(str);
unit.setName(str);
edit = reinterpret_cast<CEdit *>(GetDlgItem(IDC_INIT1));
edit->GetWindowText(str);
unit.setInit(str);
edit = reinterpret_cast<CEdit *>(GetDlgItem(IDC_CHP1);
edit->GetWindowText(str);
unit.setCHP(str);
edit = reinterpret_cast<CEdit *>(GetDlgItem(IDC_RHP1));
edit->GetWindowText(str);
unit.setRHP(str);
edit = reinterpret_cast<CEdit *>(GetDlgItem(IDC_COND1+i));
edit->GetWindowText(str);
unit.setCond(str);
units.push_back(unit);
我用它来检查一切是否正常:
vector<CUnit>::iterator pos = units.begin();
str = *pos->getName();
SetDlgItemText(IDC_NAME2, str );