草庐IT

EidosValue_Int_vector

全部标签

c++ - 如何将 unsigned char[] 转换为 std::vector<unsigned char>

我正在尝试将其传递给我的项目的另一部分,该部分要求它是一个vectorunsignedcharvch[65];unsignedintsize()const{returnGetLen(vch[0]);}constunsignedchar*begin()const{returnvch;}constunsignedchar*end()const{returnvch+size();std::vectorRaw()const{return(vch,vch+size());}我得到了错误couldnotconvert'(constunsignedchar*)(&((constCPubKey*)th

c++ - 隐式转换将符号 'int"更改为 'unsigned int"

我正在使用clang++编译程序,我需要在clang++中正确编译它。我在其他编译器上没有错误。代码中的错误行是memset(grid_,0,sizeof(int)*x_quadrants*y_quadrants);整个函数是这样的:Ocean::Ocean(intnum_boats,intx_quadrants,inty_quadrants){grid_=newint[x_quadrants*y_quadrants];memset(grid_,0,sizeof(int)*x_quadrants*y_quadrants);x_quadrants_=x_quadrants;y_quadr

c++ - 如何从数组中的特定值创建 vector ?

我将从代码开始:#include#includeusingnamespacestd;structA{intcolor;A(intp_f):field(p_f){}};intmain(){Ala[4]={A(3),A(5),A(2),A(1)};std::vectorlv={begin(la).color,end(la).color};//Iwouldliketocreatevectorfromspecificvaluefromarraylafor(std::vector::iteratorit=fifth.begin();it!=fifth.end();++it)std::cout通常

结构编译器错误 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++ 将 Lambda 与 vector 中的函数指针区分开来

我正在编写一个小的事件管理器类,我在其中将一些函数指针存储在一个vector中。我用std::function作为vector类型,我测试了在其中插入lambdas和普通函数并且它有效:voidt(intp){/*things*/}[...]event.bind([](intp){/*things*/});event.bind(t);现在,(在某个时候我需要删除lambda而不是函数,)我的问题是:是否可以将lambda与函数区分开来?如果是,怎么做?编辑:既然我澄清了我的疑惑,这个问题就如题所示 最佳答案 真正的答案是:你不想这样

c++ - 对象 vector 的析构函数

您好,我在类(class)Ordinateur中有一个*Composantvector:classOrdinateur{stringtype;vectorComposants;...}我该如何编写我的析构函数?我在StackOverflow上阅读了很多相互矛盾的答案,所以我有点迷茫。第一个版本:virtual~Ordinateur(){for(inti=0;i第二版virtual~Ordinateur(){Composants.clear();}关于:virtual~Ordinateur(){for(inti=0;i我想避免内存泄漏...... 最佳答案

c++ - 将 float 转换为 int,还是将 int 转换为 float?

我可以将常量定义为float或32位uint:constfloatSecondsPerMinute=60.0F;或constuint32SecondsPerMinute=60U;const用在一些期望int的方程和一些期望float的方程中。我想让我的编译器和静态分析工具满意,所以我会根据需要将其static_cast为适当的类型。是将const定义为float并转换为int更好,还是将其定义为int并转换为float?这有什么不同,还是这更多是个人意见?假设常量与int和float的使用次数相同。 最佳答案 模板怎么样:templ

c++ - 线性搜索通过 vector[i] 得到 0ms 响应,而 vector.at(i) 得到时间

我必须补充一点:我调用了线性搜索15000次,每次迭代时我查找的最低范围高达50000。因此意味着在第一次迭代中有15000*50000次查找。这应该需要超过0毫秒的时间。我有这个基本的线性搜索:boollinearSearch(std::vector&primes,intnumber,intrange){for(inti=0;i我花时间使用:voidtimeLinearSearch(std::vector&primes){clock_tstart,stop;size_tNRND=15000;//15000primesperclockfor(intN=50000;N这里的问题是耗时是0

c++ - vector 对统一初始化

我有一个集合定义为-usingParameters=std::vector;usingGroup=std::pair;std::vectorinputs;我的意图是使用像这样的语句inputs.push_back(group0/*Whatgoesinhere?*/);inputs.push_back(group1/*Whatgoesinhere?*/);如何使用初始化列表初始化group0和group1?像这样的代码似乎不起作用inputs.push_back(std::make_pair("group0",{1,2,3,4}));编辑:有关于vector对初始化的问题,但我看不到st

c++ - std::future<neither::Either<int, std::string>> 段错误

本题中的代码使用了Either在这里找到实现:https://github.com/LoopPerfect/neither.明确地说,我怀疑这是这个特定库的问题,否则我会在那里制造问题。以下代码段按预期工作:std::futuref=std::async(std::launch::async,[](){return"test";}std::cout下面会产生一个段错误:std::future>f=std::async(std::launch::async,[](){returnneither::Either(neither::right(std::string("test")));})