c++ map查找遍历删除
来源:互联网 发布:大数据应用支撑平台 编辑:程序博客网 时间:2024/06/10 19:35
// ConsoleApplication3.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include <iostream>#include<map>#include <string> using namespace std;void map_insert(map<string, string> *mapStudent, string index, string x){ mapStudent->insert(map<string, string>::value_type(index, x));}int _tmain(int argc, _TCHAR* argv[]){ char tmp[32] = ""; map<string, string> mapS; map_insert(&mapS, "one", "xu hai tao"); map_insert(&mapS, "two", "hunk xu"); map_insert(&mapS, "san", "hai tao gao ruan"); map<string, string>::iterator iter; iter = mapS.find("san"); //查找 cout << "查找" << endl; if (iter != mapS.end()){ cout << "find the element" << endl; cout << "it is:" << iter->second << endl; } else{ cout << "not find the element" << endl; } //遍历 cout << "遍历" << endl; for (iter = mapS.begin(); iter != mapS.end(); iter++){ cout << "| " << iter->first << " | " << iter->second << " |" << endl; } //先删除再遍历 cout << "删除" << endl; iter = mapS.find("san"); if (iter != mapS.end()){ cout << "find the element" << endl; cout << "delete the element" << endl; mapS.erase(iter); } else{ cout << "not find the element" << endl; } for (iter = mapS.begin(); iter != mapS.end(); iter++){ cout << "| " << iter->first << " | " << iter->second << " |" << endl; } getchar(); return 0;}
上面代码运行结果如下:
FR:海涛高软(hunk Xu) QQ技术交流群:386476712
阅读全文
0 0
- c++ map查找遍历删除
- map常用操作——添入、删除、查找、遍历
- map循环遍历删除
- 二叉排序树的插入、查找、删除、遍历(C语言版)
- c标签遍历map
- c标签遍历map
- 关于map的遍历 删除
- map的遍历与删除
- map遍历删除异常:ConcurrentModificationException
- Map遍历与删除元素
- c++map查找元素
- C++map遍历删除数据(删除被2整除的键值对)
- BST 插入删除查找遍历
- 二叉查找树(插入、查找、遍历、删除.........)
- 在遍历C++map中删除元素算法(简单例子)
- C++:在遍历/循环中删除map元素, 如何避免iter 迭代器失效
- C++:在遍历/循环中删除map元素, 如何避免iter 迭代器失效
- C语言实现顺序表的插入、删除、查找、遍历等基本操作
- 关于CSDN怎么获得积分和C币的方法
- postgresql数据库常用操作命令及SQL语言
- 微服务(二)--redis-client
- Intellij IDEA(android studio) svn的使用记录
- No-ip的使用(解决没有固定ip问题)
- c++ map查找遍历删除
- 物体检测 DSOD论文 1708.01241的翻译 (2)
- Gradle错误(三)
- PostgreSQL
- 使用花生壳实现内网映射,搭建Windows平台下的服务器环境
- Linux下搭建vsftp配置文件详解
- mysql中删除数据表数据的两种方式
- java--线程--锁-synchronize
- CSS基础(3.边框设置)