vc中list的使用方法总结

vc中list的使用方法总结

ID:21973174

大小:167.50 KB

页数:23页

时间:2018-10-26

vc中list的使用方法总结_第1页
vc中list的使用方法总结_第2页
vc中list的使用方法总结_第3页
vc中list的使用方法总结_第4页
vc中list的使用方法总结_第5页
资源描述:

《vc中list的使用方法总结》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库

1、这儿天在做阁像处理方而的研宄,其屮有一部分是关于阉像分割方而的,阁像目标在分割出来之后要做进一步的处理,因此有必要将目标图像的信息保存在一个变量里面,一开始想到的是数组,但是马上就发现使用数组的缺点:数组长度固定,动态分配内存很容易导致错误发生。最重要的一点是我要保存目标图像的每一点的坐标值,使川数组就有点无能为力了。因此到百度、Google大神上面找思路,终于被我发现在C++的标准库里面还有这么一个模板类:list,下而就是对找到的资料的汇总和加工。vc6自带的msdn帮助文档的解释以T是引自msdn帮助文档(中文是我自己翻译的,错误之处请包涵。):The

2、templateclassdescribesanobjectthatcontrolsavarying-lengthsequenceofelementsoftypeT.Thesequenceisstoredasabidirectionallinkedlistofelements,eachcontainingamemberoftypeT.本模板类描述了一个对象,这个对象是类型为T的可变长度的序列元素。这个序列采用双向链表的方式存储每一个元素,其屮每一个元素的数据流行都是T。Theobjectallocatesandfreesstorageforthesequen

3、ceitcontrolsthroughaprotectedobjectnamedallocator,ofclassA.Suchanallocatorobjectmusthavethesameexternalinterfaceasanobjectoftemplateclassallocator.Notethatallocatorisnotcopiedwhentheobjectisassigned.对序列对象的分配和释放操作通过一个受保护的对象allocator进行。这样一个allocator对象必须有相同的外部接U作为一个模板类分配器的对象。注意:当对象被分配

4、之后allocator不能被复制。Listreallocationoccurswhenamemberfunctionmustinsertoreraseelementsofthecontrolledsequence.Inallsuchcases,onlyiteratorsorreferencesthatpointaterasedportionsofthecontrolledsequencebecomeinvalid.当一个成员要进行insert或者erase操作吋,列表的重新分配操作发生。在这种情况下,只有迭代器或者引用所指向的要删除的对象的指针变为无效。ms

5、dn帮助文档自带的例子下妞为msdn帮助文档中自带的一个例子,该例展示了如何使用迭代器读取列表中的元素和进行插入操作。#include〈list〉#includeusingnamespacestd;typedeflistLISTINT;voidmain(){intrgTest1[]={5,6,7};intrgTest2[]={10,11,12};LISTINTlistlnt;LISTINTlistAnother;LISTINT::iteratori;//Insertoneatatimelistlnt.insert(listlnt

6、.begin(),2);listlnt.insert(listlnt.begin(),1);listlnt.insert(listlnt.end(),3);//123for(i=listlnt.begin();i!=Iistlnt.end();++i)cout«*i«"cout«endl;//Insert3fourslistlnt.insert(listlnt.end(),3,4);//123444for(i=listlnt.begin();i!=Iistlnt.end();++i)cout«*i«"cout«endl;//Insertanarrayinth

7、erelistlnt.insert(listlnt.end(),rgTestl,rgTestl+3);//123444567for(i=listlnt.begin();i!=Iistlnt.end();++i)cout«*i«"n;cout«endl;//InsertanotherLISTINTlistAnother.insert(listAnother.begin(),rgTest2,rgTest2+3);listlnt.insert(listlnt.end(),listAnother.begin(),listAnother.end());//123444

8、567101112for(i=listlnt.beg

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。