1 / 25
文档名称:

VC 中list的使用方法总结.doc

格式:doc   大小:47KB   页数:25页
下载后只包含 1 个 DOC 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

VC 中list的使用方法总结.doc

上传人:63229029 2017/4/14 文件大小:47 KB

下载得到文件列表

VC 中list的使用方法总结.doc

相关文档

文档介绍

文档介绍:这几天在做图像处理方面的研究, 其中有一部分是关于图像分割方面的, 图像目标在分割出来之后要做进一步的处理, 因此有必要将目标图像的信息保存在一个变量里面, 一开始想到的是数组, 但是马上就发现使用数组的缺点: 数组长度固定, 动态分配内存很容易导致错误发生。最重要的一点是我要保存目标图像的每一点的坐标值,使用数组就有点无能为力了。因此到百度、 Google 大神上面找思路,终于被我发现在 c++ 的标准库里面还有这么一个模板类: list ,下面就是对找到的资料的汇总和加工。 vc6 自带的 msdn 帮助文档的解释以下是引自 msdn 帮助文档(中文是我自己翻译的,错误之处请包涵。): The template class describes an object that controls a varying-length sequence of elements of type T. The sequence is stored asa bidirectional linked list of elements, each containing a member of type T. 本模板类描述了一个对象, 这个对象是类型为 T 的可变长度的序列元素。这个序列采用双向链表的方式存储每一个元素,其中每一个元素的数据流行都是 T。 The object allocates and frees storage for the sequence it controls through a protected object named allocator, of class A. Such an allocator object must have the same external interface as an object of template class allocator. Note that allocatoris not copied when the object is assigned. 对序列对象的分配和释放操作通过一个受保护的对象 allocato r 进行。这样一个 allocato r 对象必须有相同的外部接口作为一个模板类分配器的对象。注意:当对象被分配之后 allocator 不能被复制。 List reallocation occurs when a member function must insert or erase elements of the controlled sequence. In all such cases, only iterators or references that point at erased portions of the controlled sequence e invalid. 当一个成员要进行 insert 或者 erase 操作时, 列表的重新分配操作发生。在这种情况下, 只有迭代器或者引用所指向的要删除的对象的指针变为无效。 msdn 帮助文档自带的例子下面为 msdn 帮助文档中自带的一个例子, 该例展示了如何使用迭代器读取列表中的元素和进行插入操作。#include <list> #include <iostream> using namespace std ; typedef list<int> LISTINT; void main() { int rgTest1[] = {5,6,7}; int rgTest2[] = {10,11,12}; LISTINT listInt; LISTINT listAnother; LISTINT::iterator i; // Insert one ata time ((), 2); ((), 1); ((), 3); //123 for (i= (); i != (); ++i) cout << *i << " "; cout << endl; // Insert 3 fours ((), 3, 4); //123444 for (i= (); i != (); ++i) cout << *i << " "; cout << endl; // Insert an array in there ((), rgTest1, rgTest1 +