您的位置:首页 > 其它

用容器去遍历一个学生信息的结构体。

2016-05-04 16:50 197 查看
需求是这样的,

学生上下车的时候,我需要记录该学生是上车,还是下车。

方法:用一个容器,当学生刷卡时候,先遍历该容器,看能否找到该学生信息的记录,如果没有,那么就是上车,并增加该记录;如果有,就是下车,并清除该记录。

过程:

 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));     

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  容器 map