#include <iostream>
#include <map>
#include <string> using namespace std; #define N_K 10 typedef struct {
int a;
char b[]; } Data_t; void makeData(Data_t *d)
{
int i;
for (i=;i<N_K;i++)
{
d[i].a = i;
sprintf(d[i].b,"b=%02d",i);
}
} int main()
{
map<int,Data_t> m;
Data_t d[N_K];
Data_t *p;
pair<map<int, Data_t>::iterator, bool> insertPair; makeData(d);
for (int i=;i<N_K;i++)
{
m.insert(pair<int, Data_t>(i, d[i]));
} //验证插入,map不允许重复
insertPair = m.insert(pair<int, Data_t>(, d[]));
if(insertPair.second == true)
cout<<"Insert Successfully"<<endl;
else
cout<<"Insert Failure"<<endl; //遍历
map<int,Data_t>::iterator iter;
for(iter=m.begin(); iter!=m.end(); iter++){
cout<<iter->first<<" "<<(iter->second).b<<endl; }
//查找 修改 并删除
iter = m.find();
if(iter != m.end()){
cout<<"find 3 modify delete "<<iter->first<<" "<<(iter->second).b<<endl;
(iter->second).a = ;//map是深拷贝,所以在这里并没有修改d的数据
m.erase(iter);
} m.clear();
return ; }

STL基础3:map的更多相关文章

  1. [知识点]C++中STL容器之map

    UPDATE(20190416):写完vector和set之后,发现不少内容全部引导到map上了……于是进行了一定的描述补充与更正. 零.STL目录 1.容器之map 2.容器之vector 3.容器 ...

  2. UVa 11991:Easy Problem from Rujia Liu?(STL练习,map+vector)

    Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for example, ...

  3. Go语言基础之map

    Go语言基础之map Go语言中提供的映射关系容器为map,其内部使用散列表(hash)实现. map map是一种无序的基于key-value的数据结构,Go语言中的map是引用类型,必须初始化才能 ...

  4. STL中的map、unordered_map、hash_map

    转自https://blog.csdn.net/liumou111/article/details/49252645 在之前使用STL时,经常混淆的几个数据结构,特别是做Leetcode的题目时,对于 ...

  5. STL 中的map 与 hash_map的理解

    可以参考侯捷编著的<STL源码剖析> STL 中的map 与 hash_map的理解 1.STL的map底层是用红黑树存储的,查找时间复杂度是log(n)级别: 2.STL的hash_ma ...

  6. STL中的map和unordered_map

    STL中的map和unordered_map map 头文件:#include 原理:std::map的内部实现了一颗红黑树,有对其键值进行排序的功能,所以map是一个有序的容器,map中的每一个元素 ...

  7. Java基础关于Map(字典)的方法使用

    Java基础关于Map(字典)的方法使用 java中一般用map与hashmap来创建一个key-value对象 使用前提是要导入方法包: import java.util.HashMap: impo ...

  8. GO学习-(11) Go语言基础之map

    Go语言基础之map Go语言中提供的映射关系容器为map,其内部使用散列表(hash)实现. map map是一种无序的基于key-value的数据结构,Go语言中的map是引用类型,必须初始化才能 ...

  9. 【C++】【STL】【map】基础知识干货

    1.map简介 map是一种关联式容器,主要用于对数据一对一的映射. 2.map的构造 (1)头文件:#include<map> (2)定义:map<第一关键字,第二关键字> ...

随机推荐

  1. php递归获取目录下所有文件

    <?php function getFileList($dir){ $dir=iconv("utf-8","gb2312",$dir); if ($hea ...

  2. 第三章 列表(b)无序列表

  3. Wasserstein距离

    https://blog.csdn.net/leviopku/article/details/81388306 https://blog.csdn.net/nockinonheavensdoor/ar ...

  4. 分组背包模板题 hdu1712

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1712 第一次接触分组背包,参考博客:https://blog.csdn.net/yu121380/ar ...

  5. Websocket实现群聊、单聊

    Websocket 使用的第三方模块:gevent-websocket 群聊 ws群聊.py中的内容 from flask import Flask, request, render_template ...

  6. mysql数据库分区及测试

    1. 测试数据库是否支持分区 mysql可以通过下面语句判断是否支持分区: SHOW VARIABLES LIKE '%partition%'; 如果输出:have_partitioning   YE ...

  7. java序列化的认识(从多本书和多个博客中的总结)

    Serializable接口是java.io下的一个标记接口,一个类要被序列化必须实现这个接口.

  8. swift 数组 的一些快速方法

    1. filter (过滤器):返回符合条件的一个数组 let arr = [1,5,6,7,10,0] //写法1 let arr1 = arr.filter { (item) -> Bool ...

  9. Requested a new session but one was in progress

    作为appium初学者,估计很多人都会遇到这个错误.如何解决: 1.环境变量中去掉appium的安装路径,添加Appium\node_modules\.bin这个路径进去. 2.启动cmd 输入app ...

  10. [z]c++ 和 java 利用protobuf 通讯

    [z]http://andinker.iteye.com/blog/1979428  java端的具体步骤如下: 1.首先下载 下载protobuf 编译工具   http://code.google ...