1.遍历
vector<int>::iterator it = v.begin();
for(; it != v.end(); ++it)
{
cout<<(*it)<<" ";
}
2.find查找并删除, 通过重载==, 传入对象
InfomFind = Info("xx", "yy");
vector<Info>::iterator itTmp = find(dataVector.begin(), dataVector.end(), mFind);
if (itTmp != dataVector.end())
{
itTmp = dataVector.erase(itTmp);
}
class Info
{
public:
Info()
{
cameraIndexCode = wxEmptyString;
planId = wxEmptyString;
presetName = wxEmptyString;
presetIndex = -1;
playIndex = -1;
}
Info(wxString id, wxString code)
{
cameraIndexCode = code;
planId = id;
presetName = wxEmptyString;
presetIndex = -1;
playIndex = -1;
}
bool operator()(const Info& left, const Info& right)
{
return left.playIndex < right.playIndex;
}
bool operator==(InfoTmp)
{
if (cameraIndexCode.IsSameAs(Tmp.cameraIndexCode) || planId.IsSameAs(Tmp.planId))
{
return true;
}
return false;
}
wxString cameraIndexCode;
wxString planId;
wxString presetName;
int presetIndex;
int playIndex;
};
3.删除
for (vector<Info>::iterator it = dataVector.begin(); it != dataVector.end();)
{
if (it->xx== xx)
{
it = dataVector.erase(it);
}
else
{
++it;
}
}
4. 排序 通过重载(), 传入方法
std::sort(devs.begin(), devs.end(), Info());
5.find_if查找 通过重载(), 传入对象
class Info
{
public:
Info()
{
Name = wxEmptyString;
DeviceCount = 0;
devs.clear();
}
bool operator()(const Info & scheme)
{
return Name == scheme.Name;
}
wxString Name;
int DeviceCount;
};
List.erase(std::find_if(List.begin(), List.end(), scheme));