草庐IT

first_count

全部标签

c++ - 为什么 std::count(_if) 返回 iterator::difference_type 而不是 size_t?

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:WhydoestheC++standardalgorithm“count”returnaptrdiff_tinsteadofsize_t?标准C++中有std::count/std::count_if算法。templatetypenameiterator_traits::difference_typecount(InputIteratorfirst,InputIteratorlast,constT&value);templatetypenameiterator_traits::difference_typec

c++ - 调试断言失败!表达式 : __acrt_first_block == header

我正在尝试测试我用GoogleTest编写的dll,当我调用其中一个测试时,它会抛出这个错误:我得出的结论是,问题在于将内存分配给vector,但我不知道如何解决这个问题,因为我对C++编程相当陌生。代码如下:#ArraysCPP11.h#ifdefARRAYSCP11_EXPORTS#defineARRAYSCP11_API__declspec(dllexport)#else#defineARRAYSCP11_API__declspec(dllimport)#endif__declspec(dllexport)voidremoveWhiteSpaces(std::vectorv,st

c++ - 使用 vm.count() 时始终存在具有默认值的 Boost 程序选项

我一直在尝试使用boost::program_options验证我通过的选项。我的命令有几种模式,每种模式都有可以指定的相关参数。我要做的是确保这些关联的参数与模式一起传递,即unicorn--fly--magic-wings-threshold--fly是模式,--magic-wings-threshold是相关参数。我注意到的是如果--magic-wings-threshold有一个默认值,例如("magic-wings-threshold,w",po::value(&wings_thresh)->default_value(0.8,"0.8"),"Magicwingsmaximu

c++ - 我可以使用 std::pair,但重命名 .first 和 .second 成员名称吗?

我遇到的一个常见设计问题是,我将两个变量捆绑在一起,然后失去以有意义的方式引用它们的能力。std::paircords;cord.first=0;//is.firstthexorycoordinate?cord.second=0;//is.secondthexorycoordinate?我考虑过编写基本结构,但是我失去了很多std::pair:带来的好处make_pair非成员重载运算符交换得到等等有没有办法为first和second数据成员重命名或提供替代标识符?我希望利用所有接受std::pair的函数,但仍然可以通过以下方式使用它们:std::paircords;//specia

c++ - 全局变量 "count"不明确

#includeusingnamespacestd;intcount=0,cache[50];intf(intn){if(n==2)count++;if(n==0||n==1)returnn;elseif(cache[n]!=-1)returncache[n];elsecache[n]=f(n-1)+f(n-2);returncache[n];}我在gcc4.3.4中使用了这个函数,得到以下错误:prog.cpp:Infunction‘intf(int)’:prog.cpp:38:error:referenceto‘count’isambiguous在我的本地机器(mingw32)上,

c++ - unordered_map : which one is faster find() or count()?

判断unordered_map容器中是否有带有指定键的项目的最快方法是什么? 最佳答案 它们的性能大致相同。您应该使用最能表达您想要做的事情的算法。详细说明一下,一般count()会使用find()来实现。例如,在libcxx,count()实现为return(find(__k)!=end()); 关于c++-unordered_map:whichoneisfasterfind()orcount()?,我们在StackOverflow上找到一个类似的问题: h

node.js - Parse Cloud code "first"查询数组返回不同的结果

我有一个简单的查询如下:vargetGreaterQuestion=function(gid){varquery=newParse.Query(Parse.Object.extend("Question"));query.equalTo("groupId",gid);returnquery.first();}我正在准备一个包含这个函数的数组:vargroupIds=_.range(1,17);vargroupIdAndRandomNumberPack=_.map(groupIds,function(gid){return{groupId:gid,random:Math.random()

mysql - node.js-MySQL COUNT 记录数

我有以下代码。varmysql=require('mysql');varconnection=mysql.createConnection({host:'localhost',user:'root',password:'',database:'test'});connection.connect();varuserdata='24';varsql='SELECTCOUNT(*)FROMnamesWHEREage=?'connection.query(sql,[userdata],function(err,rows,fields){if(err)throwerr;console.log(

javascript - 等价于 LINQ 的 Enumerable.First(predicate)

在C#中,我们有Enumerable.First(predicate).鉴于此JavaScript代码:functionprocess(){varfirstMatch=['a','b','c'].filter(function(e){returnapplyConditions(e);}).shift();if(!firstMatch){return;}//dosomethingelse}functionapplyConditions(element){varmin=97;varmax=122;varrandom=Math.floor(Math.random()*(max-min+1)+

node.js - 错误 : unable to verify the first certificate in nodejs

我正在尝试使用URL从jira服务器下载文件,但出现错误。如何在代码中包含证书进行验证?错误:Error:unabletoverifythefirstcertificateinnodejsatError(native)atTLSSocket.(_tls_wrap.js:929:36)atTLSSocket.emit(events.js:104:17)atTLSSocket._finishInit(_tls_wrap.js:460:8)我的Nodejs代码:varhttps=require("https");varfs=require('fs');varoptions={host:'ji