C++ boost::algorithm::boyer\u moore\u搜索OO示例

C++ boost::algorithm::boyer\u moore\u搜索OO示例,c++,algorithm,boost,C++,Algorithm,Boost,请帮助我获得一个面向对象boost::algorithm::boyer\u moore\u搜索界面工作的基本示例 程序界面适合我,例如,它编译并打印“找到的模式”: #包括 #包括 #包括 int main(){ 字符串语料库(“hello world”); 字符串模式(“hello”); if(corpus.end()!=boost::algorithm::boyer\u moore\u search(corpus.begin(),corpus.end(), pattern.begin(),p

请帮助我获得一个面向对象boost::algorithm::boyer\u moore\u搜索界面工作的基本示例

程序界面适合我,例如,它编译并打印“找到的模式”:

#包括
#包括
#包括
int main(){
字符串语料库(“hello world”);
字符串模式(“hello”);
if(corpus.end()!=boost::algorithm::boyer\u moore\u search(corpus.begin(),corpus.end(),
pattern.begin(),pattern.end())
{

std::coutboyer\u moore\u search
构造函数采用单个模板类型参数,因为构造函数的两个参数都是相同的类型。您提供了两个

将您的
搜索声明更改为:

boost::algorithm::boyer_moore<std::string::const_iterator>
    search(pattern.begin(), pattern.end());
boost::algorithm::boyer\u moore
搜索(pattern.begin(),pattern.end());
它会起作用的

#include <iostream>
#include <string>
#include <boost/algorithm/searching/boyer_moore.hpp>

int main() {
    std::string corpus("hello world");
    std::string pattern("hello");

    boost::algorithm::boyer_moore<std::string::const_iterator, std::string::const_iterator>
        search(pattern.begin(), pattern.end());

    if (corpus.end() != search(corpus.begin(), corpus.end()))
    {
        std::cout << "pattern found" << std::endl;
    }
    return 0;
}
$ g++ test2.cpp 
In file included from test2.cpp:3:0:
/usr/include/boost/algorithm/searching/boyer_moore.hpp: In instantiation of ‘class boost::algorithm::boyer_moore<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >, __gnu_cxx::__normal_iterator<const char*, std::basic_string<char> > >’:
test2.cpp:10:14:   required from here
/usr/include/boost/algorithm/searching/boyer_moore.hpp:104:39: error: no type named ‘skip_table_t’ in ‘class __gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >’
         typename traits::skip_table_t skip_;
                                       ^
/usr/include/boost/algorithm/searching/boyer_moore.hpp: In instantiation of ‘boost::algorithm::boyer_moore<patIter, traits>::boyer_moore(patIter, patIter) [with patIter = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >; traits = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >]’:
test2.cpp:10:44:   required from here
/usr/include/boost/algorithm/searching/boyer_moore.hpp:63:50: error: using invalid field ‘boost::algorithm::boyer_moore<patIter, traits>::skip_’
                   suffix_ ( k_pattern_length + 1 )
                                                  ^
/usr/include/boost/algorithm/searching/boyer_moore.hpp: In instantiation of ‘corpusIter boost::algorithm::boyer_moore<patIter, traits>::do_search(corpusIter, corpusIter) const [with corpusIter = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >; patIter = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >; traits = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >]’:
/usr/include/boost/algorithm/searching/boyer_moore.hpp:92:66:   required from ‘corpusIter boost::algorithm::boyer_moore<patIter, traits>::operator()(corpusIter, corpusIter) const [with corpusIter = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >; patIter = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >; traits = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >]’
test2.cpp:12:60:   required from here
/usr/include/boost/algorithm/searching/boyer_moore.hpp:133:27: error: using invalid field ‘boost::algorithm::boyer_moore<patIter, traits>::skip_’
                 k = skip_ [ curPos [ j - 1 ]];
                           ^
boost::algorithm::boyer_moore<std::string::const_iterator>
    search(pattern.begin(), pattern.end());