#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. windows上java中文乱码-指定字符集 -Dfile.encoding=UTF-8

    jvm启动中增加参数: -Dfile.encoding=UTF-8 重启即可.

  2. Hibernate一对多关联映射的配置及其级联删除问题

    首先举一个简单的一对多双向关联的配置: 一的一端:QuestionType类 package com.exam.entity; import java.util.Set; public class Q ...

  3. python lambda 函数

    lambda 函数,也叫匿名函数,是一个不需要使用def 关键字定义的小函数.返回一个函数地址. 表达式只能有一个,参数可以有多个. a = lambda x:x*x a(3) 返回的是9

  4. HTTP协议之请求

    HTTP请求 组成 一个http请求通常由三个部分组成: 请求行(request line) 首部(header) 主体(body) 格式如下所示 <request-line><CR ...

  5. 8. String to Integer (整数的溢出)

    Implement atoi to convert a string to an integer. If no valid conversion could be performed, a zero ...

  6. Codeforces Beta Round #29 (Div. 2, Codeforces format)

    Codeforces Beta Round #29 (Div. 2, Codeforces format) http://codeforces.com/contest/29 A #include< ...

  7. SDK和API

    软件开发工具包(缩写:SDK.外语全称:Software Development Kit)一般都是一些软件工程师为特定的软件包.软件框架.硬件平台.操作系统等建立应用软件时的开发工具的集合. 笔记:开 ...

  8. SQL2008用sql语句给字段添加说明

    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'字段说明文字' , @level0type=N'SCHEMA',@l ...

  9. JDBC的学习

    JDBC —— 用Java访问数据库 一.需要用到第三方类:mysql-connector-java-5.0.8-bin.jar,并做好导包处理: 二.初始化驱动: 三.建立与数据库的链接: 四.创建 ...

  10. 克隆后没有IP

    删除文件:  /etc/udev/rules.d/70-persistent-net.rules 将/etc/sysconfig/network-scripts/ifcfg-eth0 中的HWADDR ...