#include <iostream>
#include <vector>
#include <list>
#include <map>
using namespace std; void test_map(); struct Person{
string name;
int age;
}; int main()
{
vector<Person> vs;
//list<Person> vs; Person a, b;
a.name = "xiaoa";
a.age = ; b.name = "xiaob";
b.age = ; vs.push_back(a);
vs.push_back(b); vector<Person>::iterator it;
for(it=vs.begin(); it!=vs.end(); it++)
{
cout << (*it).name << "\t" << (*it).age << endl;
cout << it->name << "\t" << it->age <<endl;
}
cout << "#########################" << endl;
typedef vector<Person>::iterator PI;
for(PI i=vs.begin(); i!=vs.end(); i++)
{
cout << (*i).name << "\t" << (*i).age << endl;
cout << i->name << "\t" << i->age <<endl;
}
cout << "#########################" << endl;
test_map();
return ;
} void test_map()
{ map<string, Person> records; Person a, b;
a.name = "xiaoa";
a.age = ; b.name = "xiaob";
b.age = ; records.insert(pair<string, Person>(a.name, a));
records.insert(pair<string, Person>(b.name, a)); cout << "#########################" << endl; map<string, Person>::iterator rec_iter;
for(rec_iter=records.begin(); rec_iter!=records.end(); rec_iter++)
{
cout << rec_iter->first << "[" << rec_iter->second.name << rec_iter->second.age << "]" << endl;
}
}

c++ 容器类的更多相关文章

  1. laravel框架中容器类简化代码-摘自某书

    <?php //容器类装实例或提供实例的回调函数 class Container { protected $bindings = []; //绑定接口和生成相应实例的回调函数 public fu ...

  2. Delphi容器类之---TList、TObjectList、TComponentList、TClassList

    转载自:http://blog.csdn.net/iseekcode/article/details/4922001 从Delphi5开始VCL中增加了新的Contnrs单元,单元中定义了8个新的类, ...

  3. Java的容器类Collection和Map

    一,概念 JAVA集合只能存放引用类型的的数据,不能存放基本数据类型. java的容器类一共有两种主要类型,Colllection和Map. 两者的区别是:Collection是单个元素,而Map是存 ...

  4. 从基层容器类看万变不离其宗的JAVA继承体系

    以容器类为例子,可以观一叶而知秋,看看以前的前辈们是如何处理各种面向对象思想下的继承体系的.读的源代码越多,就越要总结这个继承关系否则读的多也忘得快. 首先摆上一张图片: 看到这张图很多人就慌了,难道 ...

  5. Qt容器类——1. QList类、QLinkedList类和QVector类

    在开发一个较高性能需求的应用程序时,程序员会比较关注这些容器类的运行效率,表2.1列出了QList.QLinkedList和QVector容器的时间复杂度比较. 1.QList类 QList<T ...

  6. System.Collections.Generic的各容器类的用法

    演示System.Collections.Generic的各容器类的用法. 包括:Dictionary,KeyValuePair,SortedDic tionary,SortedList,HashSe ...

  7. 为了去重复,写了一个通用的比较容器类,可以用在需要比较的地方,且支持Lamda表达式

    为了去重复,写了一个通用的比较容器类,可以用在需要比较的地方,且支持Lamda表达式,代码如下: public class DataComparer<T>:IEqualityCompare ...

  8. C++中的容器类详解

    一.STL容器类 STL(Standard Template Library)的六大组件:容器(containers).迭代器(iterators).空间配置器(allocator).配接器(adap ...

  9. Java容器类接口的选择

    我们知道Java容器类实际提供了四类接口:Map,List,Set和Queue,如下图所示,每种接口都有不止一个版本的实现,如果在实际编写程序时需要使用某种接口时该如何选择. 从Oracle的Java ...

  10. Java容器类List,ArrayList及LinkedList

    List容器类图 List是一个接口,它继承自Collection和Iterable,它的实现类有AbstractList,AbstrackSequenceList,ArrayList,LinkedL ...

随机推荐

  1. Window 中常见的dos命令

    在哪里操作dos命令:    win7---->开始---->所有程序---->附件---->命令提示符                              win7-- ...

  2. Git - Eclipse 提交工程至 GitHub

    1. 在 GitHub 新建一个工程 hello-world,repository 地址是 https://github.com/username/hello-world.git 2. 在 Eclip ...

  3. Remoting的入门教程

    注:<网摘自http://www.codesky.net/article/200411/48322.html> 基本原理 当客户端创建远程RemotableClass的一个实例,.NET框 ...

  4. Linux -Yum 命令详解

    yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及SUSE中的Shell前端软件包管理器.基於RPM包管理,能够从指定的服务器自动下载RP ...

  5. HTML中的<select>标签如何设置默认选中的选项

    方法有两种. 第一种通过<select>的属性来设置选中项,此方法可以在动态语言如php在后台根据需要控制输出结果. 1 2 3 4 5 < select  id =  " ...

  6. (转)关于redis、memcache、mongoDB 的对比

    从以下几个维度,对redis.memcache.mongoDB 做了对比,欢迎拍砖 1.性能 都比较高,性能对我们来说应该都不是瓶颈 总体来讲,TPS方面redis和memcache差不多,要大于mo ...

  7. 前端性能优化工具--DOM Monster

    当我们开发web应用的时候,性能是一个永远不能回避的问题.其实对于DOM的性能调试也是一个不可或缺的过程.使用DOM monster你只需要添加到你的”书签中“,在任何需要调试的页面点击这个书签,它就 ...

  8. Js 对象三

    一.screen对象 Width:屏幕的宽度 Height:屏幕的高度 availWidth:屏幕的有效宽度 availhHeight:屏幕的有效高度 (不包含任务栏) colorDepth:色深 二 ...

  9. Node.js 【使用npm安装一些包失败之笔记】

    镜像使用方法(三种办法任意一种都能解决问题,建议使用第三种,将配置写死,下次用的时候配置还在): 1.通过config命令 npm config set registry https://regist ...

  10. linux 输入子系统(2)----简单实例分析系统结构(input_dev层)

    实例代码如下: #include <linux/input.h> #include <linux/module.h> #include <linux/init.h> ...