c++容器
来源:互联网 发布:淘宝游戏专营怎么进入 编辑:程序博客网 时间:2024/06/08 10:35
1、vector
删除vector元素
v.erase(m,n);
两个vector合并
strTotalVec.insert(strTotalVec.end(),strVec.begin(),strVec.end());
容器赋值
vData.assign(strVec.begin(), strVec.end())
容器删除
strVec.insert(strVec.begin()+j,sName);
例子:
vector<Curve*> vCurve;
function(vCurve); //函数调用
function(vector<Curve*> &curves)
{
for(int i = 0; i < num; i++)
{
curves.push_back(new Curve[1]);
}
for(int i = 0; i < num; i++)
{
Curve *curve = curves.at(i);
//然后再给curve赋值
}
}
释放
list<obj *>::iterator ite;
- for( ite = m_list.begin(); ite != m_list.end(); ++ite)
- {
- delete (*ite);
- ite = m_list.erase(ite);
- }
容器释放内存出错: new时,一会new a() 一会new a[1] 指针和数组混乱
容器删除元素
vector<CurveSamples::CurveSample>::iterator ite;
for( ite = vCurveSample.begin()+1; ite != vCurveSample.end();)
{
CurveSamples::CurveSample one = *ite;
CurveSamples::CurveSample two = *(ite-1);
if((one.y - two.y) < 0.00001)
ite = vCurveSample.erase(ite);
else
++ite;
}
自定义容器排序
- class CompLess
- {
- public:
- bool operator ()(const TItem& stItem1, const TItem& stItem2)
- {
- return stItem1.m_i32Type < stItem2.m_i32Type;
- }
- };
- class CompGreater
- {
- public:
- bool operator ()(const TItem& stItem1, const TItem& stItem2)
- {
- return stItem1.m_i32Type > stItem2.m_i32Type;
- }
- };
sort(stItemVec.begin(), stItemVec.end(), CompLess()); //升序排序
2、Map
map<CString, int> colIndo; map<int, ColInfo> colHead;
- C++--容器
- 【C/C++】STL容器
- C++STL容器
- C ++ 读书笔记 顺序容器
- C++primer 关联容器
- C++STL容器简介
- 《C++primer》 顺序容器
- 《C++primer》关联容器
- c++stack容器介绍
- c++queue容器介绍
- c++map容器介绍
- C++MAP关联容器
- C++map容器类
- C++pair容器
- c++queue容器介绍
- C++Primer 顺序容器
- c++stack容器介绍
- C++_STL 各种容器
- Mongodb与Redis应用指标对比
- Ionic2 Angularjs2 使用echarts时IOS App 图形抖动
- Linux驱动设计ioctl函数的cmd参数不能为2
- C语言程序的结构特点
- Cocos2d-js 骨骼动画载入
- c++容器
- 2.2.7—单链表—Remove Nth Node From End of List
- zigbee 绑定表
- Visual Studio代码缩进快捷键
- 【Docker】docker创建单机版的solr和IKAnalyzer的集成
- JQuery中on和click的区别
- Vim 实用技巧,一些自己常用到的命令
- codeforces837B Flag on Berland
- 从朋友圈一道小学试题想到的