【问题标题】:Errors with regex on UbuntuUbuntu 上的正则表达式错误
【发布时间】:2015-03-13 18:51:57
【问题描述】:

我在 Ubuntu 上使用正则表达式时遇到了问题,在 Qt 平台上(我也在 Code::Blocks 上尝试过)。我正在编写控制台应用程序代码,我必须使用正则表达式。

当我输入#include <regex>时,对我来说是那个错误(我认为这是最重要的错误,但是正则表达式的错误很多):

/usr/include/c++/4.9/bits/c++0x_warning.h:32: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
 #error This file requires compiler and library support for the \
  ^

我认为我应该使用 Boost 库。我安装了 Boost:

sudo apt-get install libboost-all-dev

然后打字(我编辑了一些东西,开头写了boost::):

#include <boost/regex.hpp>

但是,不幸的是,它引起了很多错误,比如:

In function `bool boost::regex_search<__gnu_cxx::__normal_iterator<char const*, std::string>, char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >(__gnu_cxx::__normal_iterator<char const*, std::string>, __gnu_cxx::__normal_iterator<char const*, std::string>, boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags)':

我真的很困惑我该怎么做。

【问题讨论】:

    标签: c++ regex ubuntu boost


    【解决方案1】:

    您没有包含&lt;boost/regex.hpp&gt; 生成的错误消息。关于标准库提供的正则表达式标头,错误消息说明了一切:您必须至少使用 C++11,才能访问该标头。例如:

    g++ -std=c++11 -Wall -Wextra -Werror foobar.cpp
    

    【讨论】:

    • 那么,我该怎么办呢?我在终端中写了它(而不是 foobar.cpp 我写了我的文件路径),但我得到了同样的错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-31
    • 1970-01-01
    • 2016-11-19
    • 1970-01-01
    • 2013-11-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多