草庐IT

ignore_match

全部标签

c++ - 在排序的 STL 容器中查找给定键的 "best matching key"

问题我有带时间戳的数据,我需要根据时间戳进行搜索,以便获得与我的输入时间戳最接近的现有时间戳。最好这应该用STL来解决。boost::*或STL::tr1::*(来自带有Featurepack的VS9)也是可能的。带时间戳的数据示例:structSTimestampedData{time_tm_timestamp;//SortingcriterionCDatam_data;//Payload}接近stl::vector,sort()和equal_range()自map或set只允许我找到完全匹配,我不会进一步使用其中之一。所以现在我有一个vector我将数据添加到其中。在搜索之前,我使

c++ - 在 libc++ 上,为什么 regex_match ("tournament", regex ("tour|to|tournament")) 失败?

在http://llvm.org/svn/llvm-project/libcxx/trunk/test/re/re.alg/re.alg.match/ecma.pass.cpp,存在以下测试:std::cmatchm;constchars[]="tournament";assert(!std::regex_match(s,m,std::regex("tour|to|tournament")));assert(m.size()==0);为什么这个匹配会失败?在VC++2012和boost上,匹配成功。在Chrome和Firefox的Javascript上,"tournament".mat

c++ - 清除cin input : is cin. ignore不是好办法吗?

什么是清除cin输入的更好方法?我认为cin.clear和cin.ignore是个好方法?代码:voidclearInput(){cin.clear();cin.ignore(1000,'\n');//cin.ignore(std::numeric_limits::max(),'\n');}我的老师给了我这个回复:thisisbasicallysayingthatyourclearInputdoesn'tworkFYI:ignoreisNEVERagoodideaasawayofgettingridofallthatremainsonalineandyourfailingthistes

c++ - std::match_results::size 返回什么?

我对以下C++11代码有点困惑:#include#include#includeintmain(){std::stringhaystack("abcdefabcghiabc");std::regexneedle("abc");std::smatchmatches;std::regex_search(haystack,matches,needle);std::cout我希望它打印出3但我却得到了1。我错过了什么吗? 最佳答案 你得到1因为regex_search仅返回1个匹配项,size()将返回捕获组的数量+整个匹配值。你的匹配是.

c++ - gcc 和 clang 抛出 "no matching function call"但 msvc (cl) 编译并按预期工作

我写了一个小的函数模板,将不同的容器连接到一个新的容器中:#include#include#include#include#includenamespaceimpl{templatevoidjoin(OutIteratoriterator,constContainer&container,constContainers&...containers){for(constauto&item:container)*iterator++=item;join(iterator,containers...);//gccandclangcannotresolvethiscall}templatevo

c++ - 错误 : out-of-line definition of 'test' does not match any declaration in 'B<dim>'

我有一个小问题让我很烦!!我不知道下面的代码似乎有什么问题。我应该能够实现从父类(superclass)继承的功能,不是吗?但我得到error:out-of-linedefinitionof'test'doesnotmatchanydeclarationin'B'templateclassA{public:virtualdoubletest()const;};templateclassB:publicA{};templatedoubleB::test()const{return0;}我在Mac上使用clang(AppleLLVM5.1版)。 最佳答案

c++ - Visual Studio 2012 : C++ compiler ignoring user-specified include directories

我遇到常见错误fatalerrorC1083:Cannotopenincludefile:'afxres.h':Nosuchfileordirectory。搜索引擎为此显示了很多匹配项,但没有一个建议的解决方案对我有用。通常这看起来是路径问题。所以,我确保安装了相关的库,并找到了文件。使用绝对路径作为#include工作正常:#include"C:\ProgramFiles(x86)\MicrosoftVisualStudio11.0\VC\atlmfc\include\afxres.h"但是,如果我将目录(C:\ProgramFiles(x86)\MicrosoftVisualStu

c++ - 为什么 std::ios_base::ignore() 设置 EOF 位?

当我从一个流中读取所有数据,但没有尝试读取到它的末尾时,流的EOF没有设置。这就是C++流的工作方式,对吧?这就是它起作用的原因:#include#includecharbuf[255];intmain(){std::stringstreamss("abcdef");ss.read(buf,6);assert(!ss.eof());assert(ss.tellg()==6);}但是,如果我ignore()而不是read()ing数据,EOF被设置:#include#includeintmain(){std::stringstreamss("abcdef");ss.ignore(6);a

c++ - 为什么 std::sub_match<T> 公开继承自 std::pair<T, T>?

我正在阅读std::sub_match的文档并看到它公开继承自std::pair.自sub_match只是一对迭代器变成了一个字符序列,加上一些额外的功能,我可以理解它是用一个pair实现的,但为什么要使用公共(public)继承呢?从std::pair公开继承的问题与从大多数其他标准类公开继承相同:它们并不意味着要进行多态操作(特别是它们没有定义虚拟析构函数)。其他成员也将无法正常工作,即赋值运算符和交换成员函数(它们不会复制matched的sub_match成员)。为什么Boost开发人员和委员会决定实现sub_match通过公开继承pair而不是使用组合(如果他们想通过first

c++ - “no match for ' operator< '” 尝试插入到 std::set 时

我正在使用gcc4.3.3尝试编译以下代码:structtestStruct{intx;inty;booloperatorsetti;setti.insert(testStruct(10,10));return0;}我得到这个错误:/usr/include/c++/4.4/bits/STL_function.h|230|错误:‘__x我怀疑我没有像应该做的那样重载运算符,但我无法查明确切的问题。我在这里做错了什么? 最佳答案 运算符必须是const并且取一个const引用:booloperator