&引用;“没有匹配功能”;boost::regex_搜索出错,我做错了吗?

&引用;“没有匹配功能”;boost::regex_搜索出错,我做错了吗?,regex,boost,Regex,Boost,代码: #包括 #包括 int main(){ 刺激:smatch什么; boost::regex regex(“some+”,boost::regex::icase); std::string mystring=“some string”; bool search_result=boost::regex_search(mystring.begin(),mystring.end(),what,regex); } 错误消息很长,这里只有第一行: #include <string> #

代码:

#包括
#包括
int main(){
刺激:smatch什么;
boost::regex regex(“some+”,boost::regex::icase);
std::string mystring=“some string”;
bool search_result=boost::regex_search(mystring.begin(),mystring.end(),what,regex);
}
错误消息很长,这里只有第一行:

#include <string>
#include <boost/regex.hpp>
int main() {
  boost::smatch what;
  boost::regex regex("some +", boost::regex::icase);
  std::string mystring = "some     string";
  bool search_result = boost::regex_search(mystring.begin(),mystring.end(), what, regex);
}
:在函数“int main()”中:
:7:88:错误:调用“regex_search(std::basic_string::iterator,std::basic_string::iterator,boost::smatch&,boost::regex&)”时没有匹配的函数
:7:88:注:候选人包括:
在d:\boost/boost/regex/v4/regex.hpp:148:0中包含的文件中,
从d:\boost/boost/regex.hpp:31,
发件人:2:
扩展我的上述评论

该示例显式声明类型为
std::string::const_iterator
的变量,然后将它们传递给
boost::regex_search
,因此没有歧义。(和洛内斯米兹做的一样)

或者,如果您使用的是C++11,您可以调用
cbegin
cend
来消除歧义。

扩展我上面的评论

该示例显式声明类型为
std::string::const_iterator
的变量,然后将它们传递给
boost::regex_search
,因此没有歧义。(和洛内斯米兹做的一样)


或者,如果您使用的是C++11,则可以调用
cbegin
cend
来消除歧义。

我知道您试图在整个字符串中搜索正则表达式;如果是这样,这应该是可行的

<stdin>: In function 'int main()':
<stdin>:7:88: error: no matching function for call to 'regex_search(std::basic_string<char>::iterator, std::basic_string<char>::iterator, boost::smatch&, boost::regex&)'
<stdin>:7:88: note: candidates are:
In file included from d:\boost/boost/regex/v4/regex.hpp:148:0,
                 from d:\boost/boost/regex.hpp:31,
                 from <stdin>:2:
#包括
#包括
int main(){
刺激:smatch什么;
boost::regex regex(“some+”,boost::regex::icase);
std::string mystring=“some string”;
bool search_result=boost::regex_search(mystring,what,regex);
}

然后根据需要使用结果。

我知道您试图在整个字符串中搜索正则表达式;如果是这样,这应该是可行的

<stdin>: In function 'int main()':
<stdin>:7:88: error: no matching function for call to 'regex_search(std::basic_string<char>::iterator, std::basic_string<char>::iterator, boost::smatch&, boost::regex&)'
<stdin>:7:88: note: candidates are:
In file included from d:\boost/boost/regex/v4/regex.hpp:148:0,
                 from d:\boost/boost/regex.hpp:31,
                 from <stdin>:2:
#包括
#包括
int main(){
刺激:smatch什么;
boost::regex regex(“some+”,boost::regex::icase);
std::string mystring=“some string”;
bool search_result=boost::regex_search(mystring,what,regex);
}

然后根据需要使用结果。

希望对该问题有更多了解的人会回答,但会起作用。我相信编译器告诉您有两种可能的方法可以从中生成代码:(a)使用
std::string::iterator
s调用
boost::regex\u search
,以及(b)使用
std::string::cnst_迭代器调用
boost::regex_search
,无法决定哪一个更好。希望对该问题了解更多的人能够回答,但效果会更好。我相信编译器会告诉您,有两种可能的方法可以从中生成代码:(a)用
std::string::iterator
s调用
boost::regex_search
,用
std::string::cnst_iterator
s调用
boost::regex_search
,它无法决定哪个更好。另一种选择是:
boost::regex_search(mystring.begin(),mystring.end(),what,regex)另一种选择:
boost::regex_搜索(mystring.begin(),mystring.end(),what,regex)