Вопрос

I am trying to compile against the boost::regex library, but as soon as I try and use the regex_search() function, it barfs:

$ g++ -Wall -L/cygdrive/c/Users/Adrian/Downloads/boost_1_53_0/stage/lib -std=c++0x exec.cpp -lboost_regex -o exec

exec.cpp: In function ‘int main(int, char**, char**)’:
exec.cpp:32:3: error: ‘regex_serach’ is not a member of ‘boost’
makefile:3: recipe for target `exec' failed
make: *** [exec] Error 1

Here is the some sample code that brings up this error:

#include <boost/regex.hpp>

int main(int argc, char* argv[], char* env[])
{
  typedef boost::match_results<string::const_iterator> matches_t;
  typedef matches_t::const_reference match_t;
  boost::regex x("");
  string str;
  matches_t what;
  boost::match_flag_type flags = boost::match_default;
  boost::regex_serach(str.begin(), str.end(), what, x, flags);
  return 0;
}

Line 32 is the line where regex_search is on. The g++ version is 4.5.3 under cygwin. Boost version is 1.53. If I comment out the regex_search line, it compiles fine. Ideas?

Это было полезно?

Решение

#include <boost/regex.hpp>

int main(int argc, char* argv[], char* env[])
{
  typedef boost::match_results<std::string::const_iterator> matches_t;
  typedef matches_t::const_reference match_t;
  boost::regex x("");
  const std::string str;
  matches_t what;
  boost::match_flag_type flags = boost::match_default;
  regex_search(str.begin(), str.end(), what, x, flags);
  return 0;
}

Three issues - string is in std namespace, requires to be called out accordingly. Second the regex_search template defines an iterator for a const string so declare it that way. Lastly regex_search is not part of boost namespace and there was a typo in the regex_seRAch. The above compiles and executes fine against boost 1.53.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top