#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. Redis 命令 - Strings

    APPEND key value Available since 2.0.0, Time complexity: O(1). Append a value to a key 127.0.0.1:637 ...

  2. Redis 命令 - Sorted Sets

    ZADD key score member [score member ...] Add one or more members to a sorted set, or update its scor ...

  3. over Oracle

    QL code: sql over的作用及用法RANK ( ) OVER ( [query_partition_clause] order_by_clause )DENSE_RANK ( ) OVER ...

  4. Android EditText不弹出输入法焦点问题的总结

    转自:http://mobile.51cto.com/aprogram-403138.htm 看一个manifest中Activity的配置,如果这个页面有EditText,并且我们想要进入这个页面的 ...

  5. OC6_目录及文件的创建

    // // main.m // OC6_目录及文件的创建 // // Created by zhangxueming on 15/6/19. // Copyright (c) 2015年 zhangx ...

  6. IPointCollection转IPolyline

    IPointCollection转线IPolyline: IPolyline pl = new PolylineClass(); IPointCollection ptc = pl as IPoint ...

  7. Libcurl笔记五_easy模式运行原理

    1, curl_easy_init内部调用Curl_open创建一个结构体SessionHandle(里面包含了所以curl使用的数据和指针)并初始化一些数据,然后返回将其作为给外侧使用的句柄CURL ...

  8. 【C#】数据库备份及还原的实现代码【转载】

    [转载]http://www.codesky.net/article/200908/128600.html C#数据库备份及还原1.在用户的配置时,我们需要列出当前局域网内所有的数据库服务器,并且要列 ...

  9. OWIN OAuth 2.0 Authorization Server

    http://www.asp.net/aspnet/overview/owin-and-katana/owin-oauth-20-authorization-server The assumption ...

  10. hadoop filesystem 删除文件 复制文件 重命名文件

    private void moveFile(Configuration conf, String Path1, String Path2, String newname ) throws IOExce ...