C++ 用map的例子
来源:互联网 发布:工匠精神 知乎 编辑:程序博客网 时间:2024/06/05 19:35
map的基本操作函数:
一个使用map的例子:
#include <map>#include <string>#include <iostream>using namespace std;void map_insert(map<string, string>* mapStudent, string index, string x){mapStudent->insert(map<string, string>::value_type(index, x));}int main(int argc, char* argv[]){char tmp[32] = "";map<string, string> mapS;//insert elementmap_insert(&mapS, "192.168.0.128", "xiong");map_insert(&mapS, "192.168.200.3", "feng");map_insert(&mapS, "192.168.200.33", "xiongfeng");map<string, string>::iterator iter;cout<<"We Have Three Elements:"<<endl;cout<<"----------------------"<<endl;//find elementiter = mapS.find("192.168.0.33");if (iter != mapS.end()){cout<<"find the element"<<endl;cout<<"It is:"<<iter->second<<endl;}else{cout<<"not find the element:192.168.0.33.";}//see elementcout<<"Here is all of the element"<<endl;for (iter = mapS.begin();iter!=mapS.end();iter++){cout<<"|"<<iter->first<<"|"<<iter->second<<"|"<<endl;}cout<<"----------------------"<<endl;//insert anothermap_insert(&mapS, "192.168.30.23", "xf");cout<<"After we insert one element:"<<endl;cout<<"----------------------"<<endl;for (iter = mapS.begin();iter!=mapS.end();iter++){cout<<"|"<<iter->first<<"|"<<iter->second<<"|"<<endl;}cout<<"----------------------"<<endl;//delete elementiter = mapS.find("192.168.200.33");if (iter!=mapS.end()){cout<<"find the element:"<<iter->first<<endl;cout<<"delete the element:"<<iter->first<<endl;cout<<"===================="<<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;}cout<<"----------------------"<<endl;return 0;}
- C++ 用map的例子
- map的使用例子
- List<Map>的例子
- map的例子
- map 的使用例子
- 百度map的简单例子
- google map的一个例子
- 用XStream把Map转化成xml的例子
- c++map的用法
- c++map的用法
- c++map的用法
- C++map的用法
- c++map的用法
- c++map的用法
- c++Map的用法
- 【C++】map的使用
- C++map的初始化
- 简单的map-reduce的java例子
- 使用NDBUnit来帮助单元测试进行数据还原
- YUM常用命令介绍
- android.os.AsyncTask注意问题
- JavaScript/jQuery、HTML、CSS 构建 Web IM 远程及时聊天通信程序
- document读取xml文件
- C++ 用map的例子
- windows linux 源码跨平台
- 企业应用系统:C/S vs B/S三层J2EE架构之争
- log4j配置
- 谈谈Spring配置中<bean>的id和name属性的花拳秀腿
- 开发那点事系列五 - 发散思维&成就技术
- 代码感想
- hdoj 1242 Rescue
- Google Maps API 申请方式变更