草庐IT

ITERATOR

全部标签

c++ - 基于范围的 for 循环和多个迭代器

我有以下代码,表示3D应用程序中的网格(为清楚起见省略了一些代码):classMesh{public:typedefstd::vectorVertices;typedefstd::vectorElements;templateMesh(constVerticesItverticesBegin,constVerticesItverticesEnd,constElementsItelementsBegin,constElementsItelementsEnd):vertices_(verticesBegin,verticesEnd),elements_(elementsBegin,elem

c++ - 关于 C++ 中的迭代器

我从“更有效的C++”中阅读了一些内容,第18项:Inbrief,theiteratoritisanobject,notapointer,sothereisnoguaranteethat“->”canbeappliedtoit.†TheSTLdoesrequirethat“.”and“*”bevalidforiterators,however,so(*it).second,thoughsyntacticallyclumsy,isguaranteedtowork.)通常,我在迭代器上使用->,没有任何问题。谁能举个例子或解释一下? 最佳答案

结构编译器错误 vector 的 C++ 迭代器

我创建了一个包含两个变量的struct类型。我在vector中使用此数据类型,它再次存储在map中,如下所示:structA{intx;Yy;A(){};A(int_x,Y_y){x=_x,y=_y;};};typedefstd::vectorLA;typedefstd::mapMB;MBb;当我尝试使用迭代器时,例如std::vector::iteratorit=b[x].begin();编译器报错:error:noviableconversionfrom'__wrap_iter'to'__wrap_iter>*>'std::vector::iteratorit=b[x].begin

c++ - 为什么我的 Boost.Regex 搜索只报告一次匹配迭代?

我试图找出一个字符串中有多少个正则表达式匹配项。我正在使用迭代器来迭代匹配项,并使用整数来记录有多少匹配项。longintbefore=GetTickCount();stringtext;boost::regexre("^(\\d{5})\\s(\\d{8})\\s(.*)\\s(.*)\\s(.*)\\s(\\d{8})\\s(.{1})$");char*buffer;longlength;longcount;ifstreamf;f.open("c:\\temp\\test.txt",ios::in|ios::ate);length=f.tellg();f.seekg(0,ios::

C++ 如何遍历结构列表并访问它们的属性

我知道我可以像这样循环遍历字符串列表:list::iteratorIterator;for(Iterator=AllData.begin();Iterator!=AllData.end();Iterator++){cout但是我怎样才能做这样的事情呢?list::iteratorIterator;for(Iterator=AllData.begin();Iterator!=AllData.end();Iterator++){cout或者如果有人可以解释如何使用for_each循环执行此操作,那也会非常有帮助,但从我读到的内容来看它似乎更复杂。非常感谢 最佳答

C++ 列表实现

因此,我正在为编程练习构建List的实现。到目前为止我有这个:#include#includeusingnamespacestd;templateclassLink;templateclassList_iterator;templateclassList{public:typedefList_iteratoriterator;List();List(constList&l);~List();boolempty()const;unsignedintsize()const;T&back()const;T&front()const;voidpush_front(constT&x);voidp

c++ - Ruby C++ 风格的迭代器

我想遍历不同的ruby​​数组(可能还有散列)。我真的不想维护一个索引来跟踪我在每个数组中的位置。不是因为我懒,而是我习惯了C++的迭代器使用方式,我认为这种方式更不容易出错。那么有没有办法在ruby​​中获取迭代器,就像我们在c++中所做的那样(这个例子并没有做太多,但它只是为了例子):std::set::iteratoriter1=set1.begin();std::set::iteratoriter2=set2.begin();while(iter1!=set1.end()&&iter2!=set2.end(){if(iter1->timestamp>iter2->timesta

c++ - vector 迭代器不兼容

我目前正在为C++开发图形库,但现在遇到了一个问题,即在运行时的Debug模式下出现断言错误。我还在SO上查看了其他一些问题,但没有一个问题和答案能让我找到解决方案。在一些论坛上阅读后,我的印象是发生此错误是因为一旦vector内容更改,迭代器就会变得无效。(例如当使用erase()时)但是正如您在我的代码中看到的那样,我没有修改vector,只是迭代。错误在我用//ASSERTION标记的行中。奇怪的是,neighbor_it没有指向(*vertex_it)->neighbors()中的第一个对象,而是指向0xfeeefeee。通过代码调试时,我可以清楚地看到neighbors-ve

c++ - "No match for operator="试图在 C++ 中遍历映射

我正在尝试遍历定义如下的map:std::map>ridx_;现在我尝试在以下重载运算符的友元函数中遍历ridx_(它是一个类的私有(private)成员)std::ostream&operator>::iteratorit;//Thefollowingisline34for(it=m.ridx_.begin();it!=m.ridx_.end();it++)osfirst但是g++错误输出:SMatrix.cpp:34:error:nomatchfor'operator='in'it=m->SMatrix::ridx_.std::map::beginwith_Key=unsigned

c++ - C++中的循环优化技术

为了提高应用程序的性能,我们必须在开发阶段考虑循环优化技术。我想向您展示一些不同的方法来迭代一个简单的std::vectorv:带有索引的未优化循环:uint64_tsum=0;for(unsignedinti=0;i带有迭代器的未优化循环:uint64_tsum=0;std::vector::const_iteratorit;for(it=v.begin();it!=v.end();it++)sum+=*it;缓存std::vector::end迭代器:uint64_tsum=0;std::vector::const_iteratorit,end(v.end());for(it=v.