草庐IT

stl-algorithm

全部标签

C++ STL make_heap 和 pop_heap 不工作

我需要使用堆,所以我搜索了STL,但它似乎不起作用,我写了一些代码来解释我的意思:#include#include#include#includestructdata{intindice;inttamanho;};boolcomparator2(constdata*a,constdata*b){return(a->tamanhotamanho);}intmain(){std::vectormesas;datax1,x2,x3,x4,x5;x1.indice=1;x1.tamanho=3;x2.indice=2;x2.tamanho=5;x3.indice=3;x3.tamanho=2;

C++ -- STL Vector::const_iterator 为什么不使用 < xx.end()?

//displayvectorelementsusingconst_iteratorfor(constIterator=integers.begin();constIterator!=integers.end();++constIterator)cout我们可以使用constIterator吗??谢谢 最佳答案 operator仅为randomaccessiterators定义。例如,这些由std::vector提供。和std::string,本质上是将数据存储在连续存储中的容器,其中迭代器通常只不过是包装指针。提供的迭代器,例如s

c++ - 调用删除时 STL 迭代器失效的问题

STL标准定义当删除发生在诸如std::deque、std::list等容器上时,迭代器将失效。我的问题如下,假设包含在std::deque中的整数列表,以及一对指示std::deque中元素范围的索引,删除所有偶数元素的正确方法是什么?到目前为止,我有以下内容,但这里的问题是假定的结束在删除后无效:#include#includeintmain(){std::dequedeq;for(inti=0;ir(10,50);std::deque::iteratorit=deq.begin()+r.first;std::deque::iteratorend=deq.begin()+r.sec

C++ STL : Using map with priority_queue

我正在尝试通过将字母及其对应值保存到映射中然后将该映射插入到优先级队列中来实现霍夫曼编码。当我尝试声明我的队列时出现参数转换错误。我到底应该把什么作为参数?我这里有的是我最好的猜测。voidmain(){ifstreamdoc("doc.txt");mapC;charletter;while(!doc.eof()){doc.get(letter);if(letter>='a'&&letter,greater>Q(C);//alsotriedgreater>/*map::const_iteratorit;for(it=C.begin();it!=C.end();it++)coutfirs

c++ - 有序和无序的 STL 容器

很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visitthehelpcenter.关闭11年前。有序和无序STL容器之间有什么区别?

c++ - 是否可以将STL复制功能与 map 一起使用

我想知道是否有任何技巧可以使用copywithmaps将map的内容复制到数组中。因为STL映射是键值和映射值的组合,所以映射的元素形成键值对。这会阻止我们使用标准算法,如std::copy。例如下面的代码给出错误:#include#include#include#includeintmain(){std::maptest(4);test[0]=11;test[2]=1.23;test[3]=23.29;test[1]=12.12;double*test_arr=(double*)malloc(4*sizeof(double));std::copy(test.begin(),test.

c++ - 为什么 STL 在查找时会映射核心转储?

所以,在这种情况下,我需要查看一个对象是否在我的STL映射中。如果不是,我将添加它。charsymbolName[]={'H','e','l','l','o','\0'};maptheMap;if(theMap.find(symbolName)==theMap.end()){TheObjecttheObject(symbolName);theMap.insert(pair(symbolName,theObject));}当对象不在map中时,我在theMap.find上获取核心转储。据推测,如果该项目不在map中,它应该返回一个迭代器,相当于map::end这是怎么回事?海湾合作委员会

C++ STL 101 : Overload function causes build error

如果我不重载myfunc,就可以工作的简单代码。voidmyfunc(inti){std::coutv;v.push_back(1);v.push_back(2);std::vectors;s.push_back("one");s.push_back("two");std::for_each(v.begin(),v.end(),myfunc);std::for_each(s.begin(),s.end(),myfunc);return;}int_tmain(intargc,_TCHAR*argv[]){std::cout两次for_each调用都会重复以下构建错误。errorC2914

C++ STL map.find() 找不到我的东西

我构建了一个map并加载了数据。如果我遍历我看到的所有元素,它们都是有效的。但是,查找方法没有找到我的项目。我确定这是我在做的愚蠢的事情。这是片段://definitions//Iaminsertingapersonclassandusingthefirstnameasthekeytypedefstd::mapmapType;mapType_myMap;mapType::iterator_mapIter;...Person*pers=newPerson(FirstName,LastName,Address,Phone);_myMap.insert(make_pair(pers->fir

c++ - 在哪里可以下载 .h 和 .cpp 文件的 C++ STL 源代码?

我从http://www.sgi.com/tech/stl/download.html下载了STL源代码,但它只有.h用于函数声明。我在哪里可以下载.cpp文件来阅读实际的实现?例如,在STL_multimap.h或STL_map.h中,它有:templateinlinevoidswap(multimap&__x,multimap&__y){__x.swap(__y);}我想知道交换的实际实现,如__x.swap(__y);我没有看到交换的实际代码在哪里。在这里,它只是调用自己。 最佳答案 .h文件包含实现。该页面上的许多heade