用容器去遍历一个学生信息的结构体。
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));
}
学生上下车的时候,我需要记录该学生是上车,还是下车。
方法:用一个容器,当学生刷卡时候,先遍历该容器,看能否找到该学生信息的记录,如果没有,那么就是上车,并增加该记录;如果有,就是下车,并清除该记录。
过程:
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));
}
相关文章推荐
- android Google Map获取地理位置信息的方法
- Spark RDD API详解(一) Map和Reduce
- Python中map()函数浅析
- Android使用Google Map浅谈
- Erlang中的映射组Map详细介绍
- c++中容器之总结篇
- c++中map的基本用法和嵌套用法实例分析
- 百度地图给map添加右键菜单(判断是否为marker)
- JavaScript中实现Map的示例代码
- jquery中map函数与each函数的区别实例介绍
- jquery中map函数遍历数组用法实例
- jquery与google map api结合使用 控件,监听器
- jquery遍历数组与筛选数组的方法
- JavaScript中实现map功能代码分享
- 用json方式实现在 js 中建立一个map
- Android Map新用法:MapFragment应用介绍
- js Map List 遍历使用示例
- java获取web容器地址的方法
- java实现遍历Map的方法
- velocity显示List与Map的方法详细解析