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;