草庐IT

ITERATOR

全部标签

c++ - 从文件中读取文本到无符号字符数组

我一直在寻找使用OpenSSL来加密文件中的文本,并且在加密之前需要将文本放在无符号字符数组中。从文件读取文本到无符号字符数组的最简单方法是什么? 最佳答案 您的问题被标记为C和C++(这不是建设性的)。我会给出C++的答案。#include#include#includeusingnamespacestd;intmain(){ifstreamin("filename.txt");//openfilein>>noskipws;//wedon'twanttoskipspaces//initializeavectorwithapairo

c++ - 不能在函数声明中使用模板参数

我正在努力寻找以下代码无法编译的充分理由。它给了我以下错误。Error2errorC2923:'std::pair':'std::set::iterator'isnotavalidtemplatetypeargumentforparameter'_Ty1'我需要了解一下为什么C++不允许我在函数声明中使用模板参数,因为我使用set::iterator而不是set::iterator程序可以工作.#include#includeusingnamespacestd;templatevoidprint(constpair::iterator,bool>&p)//setOfInts;setOf

c++ - 在 C++11 基于范围的 'for' 循环中获取对 STL 容器元素的引用

for(Somethingsomething:setOfSomething)//OKfor(Somethingconst&something:setOfSomething)//OKfor(Something&something:setOfSomething)//ERRORerror:invalidinitializationofreferenceoftype'Something&'fromexpressionoftype'constSomething'迭代器从什么时候开始返回constSomething?它应该返回Something&或Somethingconst&。由于基于范围的“f

c++ - 为什么 std::istream_iterator 忽略换行符?

我有以下代码:#include#include#includeintmain(){std::stringstreamstr;strit(str),end;for(;it!=end;++it){std::cout输出是:[abcdef][97][98][99][100][101][102]为什么std::istream_iterator忽略换行符? 最佳答案 因为istream_iterator使用operator>>。并且istream::operator>>(char)会跳过空格,除非您取消设置流的skipws标志。(例如使用no

c++ - 在 std::map 中打印迭代器的索引

我正在使用std::map的find()方法,它返回一个迭代器。但是我需要找到的元素的索引;例如:0,对应于std::map::begin(),等等。#include#include#includeintmain(){std::mapaMap;aMap.insert(std::make_pair(100,50));aMap.insert(std::make_pair(200,40));aMap.insert(std::make_pair(300,60));std::map::iteratorit_map=aMap.find(300);if(it_map!=aMap.end())std:

c++ - 与值初始化的迭代器相比,它的定义是否明确?

下面的程序是否调用了未定义的行为?#include#includeintmain(intargc,char*argv[]){for(autoit=std::istream_iterator(std::cin);it!=std::istream_iterator();++it){std::cout这4yearoldquestion说他们不能比较:Iteratorscanalsohavesingularvaluesthatarenotassociatedwithanycontainer.[Example:Afterthedeclarationofanuninitializedpointer

c++ map/set 迭代器不可取消引用

我想向您请教,因为我是初学者,在互联网上找不到合适的答案。我收到此错误:调试断言失败-映射/设置迭代器不可取消引用在看起来像这样的行:pointA=active->pointNext(timeNext);使用pointNext()函数,我看到一切正常,并且关注active,我有:active=setS.data.end();更多信息:active是multiset::const_iteratorsetS有:setS.Q、setS.W、setS.T和setS.data,其中setS.data在方括号内有0。当我在.cpp文件中有多重迭代器声明时,在调试期间我无法进入以查看事件内部的内容,

c++ - 将 vector 迭代器转换为指针

我有一个vectorstd::vector。我想迭代vector以找到匹配项,如果找到,我想返回指向元素的指针,如下所示:constint*findint(std::vector&v,inta){std::vector::const_iteratori1,i2;i1=v.begin();i2=v.end();for(;i1!=i2;++i1){if(a==*i1){return(i1);}}return(0);}使用GNUg++2.95.3编译器编译和工作正常,但不能使用GNUg++4.9.2编译并出现以下错误:error:cannotconvert'std::vector::cons

c++ - 标准库中rbegin和end函数的区别

我有一个映射的实现,其中ID存储为值,标记为键。这使我能够利用map中的自动排序功能,并让我识别得分最高的元素的ID。for(map::iteratori=marks.begin();i!=marks.end();++i)coutfirstsecondsecondsecond产生这个输出:31234204512275211420输入序列是值的递增顺序。为什么end()不显示“1”而是显示最后输入的一对key?rbegin()和end()有什么区别? 最佳答案 rbegin实际上是容器的最后一个元素。end是容器末尾的过去。所以mar

c++ - 如何使函数参数容器独立

我正在编写一个实用程序函数,它将采用元素vector(可以是字符串、整数、double、字符)并将其连接成单个字符串并返回它。它看起来像这样:templatestd::stringconvert2Str(std::vectorconst&vec){std::ostringstreamsStream;for(size_tk=0;k我想让这个函数更通用:首先使用迭代器而不是为vector使用索引.我试过这个std::vector::const_iteratorit=vec.begin()在循环之前,编译器给了我一个错误::错误:预期;在它之前当我将上述定义更改为std::vector::c