需求是這樣的,
學生上下車的時候,我需要記錄該學生是上車,還是下車。
方法:用一個容器,當學生刷卡時候,先遍歷該容器,看能否找到該學生信息的記錄,如果沒有,那麼就是上車,並增加該記錄;如果有,就是下車,並清除該記錄。
過程:
std::map<std::string, SearchCardInfo_t>m_StudentInfo_forYTSchoolbus;
std::map<std::string, SearchCardInfo_t>::iterator iter;
iter = m_StudentInfo_forYTSchoolbus.find(cardInfo.kh);
if (iter != m_StudentInfo_forYTSchoolbus.end())
{
m_StudentInfo_forYTSchoolbus.erase(iter);//清除記錄
}
else
{
m_StudentInfo_forYTSchoolbus.insert(pair<std::string, SearchCardInfo_t>(cardInfo.kh, cardInfo));
}