用容器去遍歷一個學生信息的結構體。

需求是這樣的,

學生上下車的時候,我需要記錄該學生是上車,還是下車。

方法:用一個容器,當學生刷卡時候,先遍歷該容器,看能否找到該學生信息的記錄,如果沒有,那麼就是上車,並增加該記錄;如果有,就是下車,並清除該記錄。

過程:

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章