草庐IT

minimum_should_match

全部标签

c++ - 在 unordered_set 中插入一个新元素 : should the hint be end()?

如果我确定某个值还没有进入unordered_set,并且我要插入这样的值,传递这个集合end()是否正确>迭代器作为提示?编辑:代码:#includeusingnamespacestd;unordered_setsomeset;intmain(){autoit=someset.find(0);if(it==someset.end())someset.insert(it,0);//correct?possibleperformanceboostifthesetisactuallypopulated?} 最佳答案 我想,你可以简单地调

c++ - 如何到 "pattern match"一个模板?

通常在模板中你想知道整个类型,但在我的例子中我需要知道更多,并且想“分解”类型。举个例子:template>Tget_front(Collectionconst&c){returnc.front();}我怎样才能做到这一点?注意:我需要它来自动推断类型,而不是传递类似,int>的东西 最佳答案 编辑:最后可以找到C++0x方式。编辑2:我很愚蠢,在答案的末尾可以找到比所有这些特征内容更短的C++98/03方法。p>如果你想让你的函数适用于任意标准库容器,你需要拿出一些模板枪。问题是,不同的容器采用不同数量的模板参数。std::vec

c++ - 使用 std::string 时为 "error: no match for ‘operator<<"

你能帮我找出下面代码中的问题吗(代码类似于C++streamasaparameterwhenoverloadingoperator):#include#includeclasslogger{public:voidinit(std::ostream&ostr){stream=&ostr;}templatelogger&operator一切正常,直到我取消注释包含“world”的行。在这种情况下,GCC产生错误:在...中与“operator有意思的是VS2008对这段代码没有问题谢谢! 最佳答案 std::string("world"

c++ - "more than one instance of overloaded function "标准::战俘 "matches the argument list"

使用C++,我尝试#defineTINYstd::pow(10,-10)我为定义了TINY的类(.h)提供了带有#include和命名空间信息的代码#pragmaonce#include"MMath.h"#include#include#includeusingnamespacestd;#defineTINYstd::pow(10,-10)我在.cpp文件中的一些函数实现中使用了TINY,而TINY给出了错误IntelliSense:morethanoneinstanceofoverloadedfunction"std::pow"matchestheargumentlist什么是正确的

c++ - 错误 : no matching function for call to

这是我的错误...“在构造函数‘NumGame::NumGame(int&)’中:错误:没有匹配函数来调用“Category::Category()””我在这里看了几个类似的问题,但似乎找不到答案。我有一个基类Category,NumGame是从它继承的,但不会编译。classCategory{public:voidvirtualselection(int&);Category(int&);virtual~Category(){};private:intmyRandNum;};Category::Category(int&a){myRandNum=a;}voidCategory::se

java tor String.Match()用于整数

我正在尝试从我的OCR文本检测器中获取某些数字。到目前为止,我还无法成功提取某种格式的数字。该数字看起来与此5225612832654455相似,通常该格式可能像xxxxxxxxxxxxxxxx我需要一个字符串匹配的正则是获得这样的数字。注意:图源还有其他数字,我需要避免在这里捕获是方法ListtextComponents=text.getComponents();for(TextcurrentText:textComponents){floatleft=translateX(currentText.getBoundingBox().left);floatbottom=translateY(c

c++ - 算法的正确性和逻辑 : minimum steps to one

问题陈述:对于正整数,您可以执行以下3个步骤中的任何一个。从中减去1。(n=n-1)如果它能被2整除,则除以2。(如果n%2==0,则n=n/2)如果它能被3整除,则除以3。(如果n%3==0,则n=n/3)给定一个正整数n,您的任务是找到使n等于1的最少步数。我的递归解决方案(在C++中)比较了N可以被3整除的所有3种情况,而一般解决方案只比较2,但仍然给出了正确的解决方案。intmin_steps(intN){if(N==1)return0;else{if(N%3==0){if(N%2==0)return(1+min(min_steps(N/3),min_steps(N/2),mi

c++ - 我们可以使用异构查找比较器对 STL 关联容器执行 "partial-match"搜索吗?

所以我在STL的关联容器(自C++14起)中寻找对异构查找的支持,并对我们可以做什么和不应该做什么感到有点困惑。以下片段#include#include#includestructpartial_compare:std::less{//"full"key_typecomparisondonebystd::lessusingless::operator();//"sequence-partitioning"comparison:onlycheckpair'sfirstmemberbooloperator()(std::pairconst&lhs,intrhs)const{returnlh

c++ - STL 中的 VS 编译器错误 C2752 ("more than one partial specialization matches")

不知何故,我喜欢这些显示(基本?)问题的“最短”程序。在VS2008中测试一些模板代码时出现了这个错误(它也已在VS2010和VS2012中得到确认,见下文):c:\programfiles(x86)\microsoftvisualstudio9.0\vc\include\xmemory(225):errorC2752:'std::_Ptr_cat_helper':morethanonepartialspecializationmatchesthetemplateargumentlistwith[_T1=constfloat(**),_T2=constfloat(**)]我可以将问题归

C++ - 错误 E2285 : Could not find a match for 'tolower(char *)' in function parseInput(fstream &)

给定以下代码:voidparseInput(fstream&inputFile){constintLENGTH=81;charline[LENGTH];while(!inputFile.fail()){inputFile.getline(line,LENGTH);line=tolower(line);cout编译时出现这个错误:ErrorE2285:Couldnotfindamatchfor'tolower(char*)'infunctionparseInput(fstream&)我知道它返回一个int,而不是int[],这是否意味着我不应该使用getline而应该将输入字符转换为字符