【问题标题】:Why doesn't g++ see boost::regex_search() function?为什么 g++ 看不到 boost::regex_search() 函数?
【发布时间】:2013-05-19 12:05:16
【问题描述】:

我正在尝试针对 boost::regex 库进行编译,但是一旦我尝试使用 regex_search() 函数,它就会出错:

$ 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

这里是一些导致此错误的示例代码:

#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;
}

第 32 行是 regex_search 所在的行。 cygwin下的g++版本是4.5.3。升压版本是 1.53。如果我注释掉 regex_search 行,它编译得很好。想法?

【问题讨论】:

    标签: c++ g++ boost-regex


    【解决方案1】:
    #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;
    }
    

    三个问题 - 字符串在 std 命名空间中,需要相应地调用。其次,regex_search 模板为 const 字符串定义了一个迭代器,因此以这种方式声明它。最后 regex_search 不是 boost 命名空间的一部分,并且 regex_seRAch 中有错字。以上针对boost 1.53编译并执行良好。

    【讨论】:

    • 第一个不是问题,因为我忘了包括 #include&lt;string&gt;using namespace std;。我没有意识到迭代器没有得到 const 提升。人力资源管理系统。并感谢您接住我的打字机。哇!
    • 啊,我明白了。 This example 说明了原因。
    猜你喜欢
    • 1970-01-01
    • 2020-03-08
    • 1970-01-01
    • 2010-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-08
    相关资源
    最近更新 更多