STL中map的基本操作
来源:互联网 发布:java基础是什么 编辑:程序博客网 时间:2024/06/05 11:58
#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 element
map_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 Third Element:" << endl;
cout << "-----------------------------" << endl;
//find element
iter = mapS.find("192.168.0.33");
if (iter != mapS.end()) {
cout << "find the elememt" << endl;
cout << "It is:" << iter->second << endl;
} else {
cout << "not find the element" << endl;
}
//see element
for (iter = mapS.begin(); iter != mapS.end(); iter++ ) {
cout << "| " << iter->first << " | " << iter->second << " |" << endl;
}
cout << "-----------------------------" << endl;
map_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 element
iter = mapS.find("192.168.200.33");
if (iter != mapS.end()) {
cout << "find the element:" << iter->first << endl;
cout << "delete 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;
}
- STL中map的基本操作
- [C++][STL][map]C++ map的基本操作和使用
- STL中map的基本应用
- STL 中map 容器的基本用法
- STL中map的erase操作
- STL中map容器的操作
- STL: Map 的操作
- C++ 【STL】 map的基本操作和使用
- C++ stl map的基本操作和使用
- stl map的基本使用
- C++ STL Map 基本操作和使用
- STL中map,set的基本用法示例
- c++ stl中map容器的基本用法
- STL之Map:Map的基本用法
- map的基本操作
- Map的基本操作
- STL Map 的简单操作
- 小心使用STL中map的[]操作符
- Valid Parentheses
- Java 7之基础 - 强引用、弱引用、软引用、虚引用
- 安卓开发(10)---深入解析布局文件
- ProgressBar的使用
- TPS和事务响应时间的关系【转】
- STL中map的基本操作
- listview原理及优化
- eclipse10秒启动配置
- gdb发现Column count doesn't match value count at row 1问题
- Apache乱码解决
- java多线程 Thread 和Runnable
- java内存泄漏的定位与分析
- [转]知乎上的一个怎么面试iOS工程师的问题
- POJ1088 滑雪(递归 + 记忆化搜索)