0

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?

ks1322
  • 33,961
  • 14
  • 109
  • 164
Adrian
  • 10,246
  • 4
  • 44
  • 110

1 Answers1

0
#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.

parry
  • 504
  • 3
  • 9
  • The 1st is a non-issues as I forgot to include the `#include` and `using namespace std;`. I didn't realise that the iterator didn't get const promoted. Hrm. And thanks for catching my typeo. Doh! – Adrian May 24 '13 at 02:09
  • Ah, I understand. [This example](http://stackoverflow.com/a/14571400/1366368) shows why. – Adrian May 24 '13 at 02:23