C++容器例子

来源:互联网 发布:mac 开机 option 编辑:程序博客网 时间:2024/06/06 19:43

参考:

http://cjbskysea.blogbus.com/logs/39993224.html

 

例1、vector

运行结果:

yuan@yuan:~/work/test> ./cpp_vector
vector   部分
1 2 3 4 5 1 2 3 4 5
Find: 4  Pos:vecIter*****
1 2 3 4 5 1 2 3

--------------------

Pos处不能得到地址的原因是,

vector不是指针,不可能返回地址,返回的是一个拷贝的对象

具体解释:
http://zhidao.baidu.com/question/154836253.html?fr=ala0



例2、list

运行结果:
yuan@yuan:~/work/test> ./cpp_list
list 部分
5 4 3 2 1 1 2 3 4 5
Can`t find 6 in intList.
4 3 2 1 1 2 3 4