初学C++ container(容器) 顺序容器

来源:互联网 发布:网络舆情监测员工资 编辑:程序博客网 时间:2024/05/29 14:45

要使用C++的容器首先包含头文件,以vector为例:

#include <vector>std::vector<Point> ivct(3, Point(1, 2)); //初始化,要求有Point(x,y)的函数std::vector<Point> iVct(2); //要求Point有默认构造函数std::vector<Point> empty;   //Point即使没有默认构造函数也不会报错std::vector<Point> iVt(ivct.begin(), ivct.end());std::vector<Point>::iterator itv;itv = iVt.begin(); 


在vector或deque容器中添加元素时,可能导致某些或全部迭代器失效。因此假设所有迭代器失效是最安全的做法。

原创粉丝点击