需求是这样的,
学生上下车的时候,我需要记录该学生是上车,还是下车。
方法:用一个容器,当学生刷卡时候,先遍历该容器,看能否找到该学生信息的记录,如果没有,那么就是上车,并增加该记录;如果有,就是下车,并清除该记录。
过程:
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));
}