我已经阅读了一些关于CList的教程,它似乎比C ++ STL的std::list
功能丰富得多。特别引起我注意的是我可以通过值搜索CList并返回一个位置(假设所有值都是唯一的,在我的情况下总是如此)。我正在尝试使用boost智能指针列表。使用指针值查询列表或快速更改位置值以跳转到元素对我来说非常方便。是否有任何专门的列表库可以让我这样做?
提前致谢!
答案 0 :(得分:3)
是的,有。它位于标准标题<algorithm>
中,即函数模板std::find
。
答案 1 :(得分:2)
我不需要调用MFC比STL更丰富的功能,但它肯定有利于成员方法的设计和自由函数和模板接口的继承。
您可以使用algorithm中的功能搜索元素,例如std::find
,std::find_if
等,这些功能通常也会在vector
等STL容器上运行。
根据您的具体情况,您可能需要执行以下操作:
#include <list>
#include <algorithm>
typedef std::list<int> IntList;
int nums[] = { 1,2,3,4,5,6,7,8,9 };
IntList numbers(nums, nums + sizeof(nums) / sizeof(int));
IntList::const_iterator found = std::find(numbers.begin(), numbers.end(), 7);
if (found != numbers.end())
;// then found is an iterator to the element containing the value 7
else
;// didn't find
现在,就Linux上的MFC行为而言,我建议使用Qt。这是一个庞大的跨平台框架,有很多有用的东西。更好的是它的开源和免费,并附带它自己的IDE,称为QtCreator,也不是一半坏。