包含头文件
#include <iostream>
#include <string>
#include <map>
代码
std::map<int, std::string> mapStudent;
//插入数组,数组的下标实际上就是索引
mapStudent[4] = "[email protected]";
std::map<int, std::string>::iterator iter;
iter = mapStudent.find(5);
//访问不到数据的判断
if (iter == mapStudent.end()) return;
std::cout << iter->second << std::endl;
//删除该记录
mapStudent.erase(iter);
注意:
对于容器而言,是判断是否为end(),如果无法find到数据
时间: 2025-02-01 09:05:08