简体   繁体   English

使用regex_replace函数时出错<tr1/regex>

[英]error while using regex_replace function from <tr1/regex>

#include <string>
#include <tr1/regex>

#include "TextProcessing.h"

const std::string URL_PATTERN("((http://)[-a-zA-Z0-9@:%_\\+.~#?&//=]+)");
const std::string REPLACEMENT("<a href=\"$&\"\">$&</a>");

std::string textprocessing::processLinks(const std::string & text)
{

    // essentially the same regex as in the previous example, but using a dynamic regex
    std::tr1::regex url(URL_PATTERN);

    // As in Perl, $& is a reference to the sub-string that matched the regex
    return std::tr1::regex_replace(text, url, REPLACEMENT);
}

I'm using mingw gcc copiler 4.5.0 version. 我正在使用mingw gcc copiler 4.5.0版本。

I've got the follow error: 我有以下错误:

%DEV%> mingw32-make all
g++  -Wl,--enable-auto-import -Wall -Wextra -std=c++0x -pedantic -Werror -c  -I./include TextProcessing.cpp
cc1plus.exe: warnings being treated as errors
c:\dev\mingw\bin\../lib/gcc/mingw32/4.5.0/include/c++/tr1_impl/regex:2390:5: error: inline function '_Out_iter std::tr1::regex_replace(_Out_iter, _Bi_iter, _Bi_iter, const std::tr1::basic_regex<_Ch_type, _Rx_traits>&, const std::basic_string<_Ch_type>&, std::tr1::regex_constants::match_flag_type) [with _Out_iter = std::back_insert_iterator<std::basic_string<char> >, _Bi_iter = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >, _Rx_traits = std::tr1::regex_traits<char>, _Ch_type = char, std::tr1::regex_constants::match_flag_type = std::bitset<11u>]' used but never defined
mingw32-make: *** [TextProcessing.o] Error 1
Process mingw32-make exited with code 2

Yup, in my g++ include files I also see that regex_replace is declared and not defined. 是的,在我的g ++包含文件中我也看到regex_replace已声明且未定义。 For me, it's in the file /usr/include/c++/4.4.4/tr1_impl/regex . 对我来说,它位于文件/usr/include/c++/4.4.4/tr1_impl/regex中。 Just above the declaration is a Doxygen comment section which includes: 声明正上方是Doxygen评论部分,其中包括:

/** @todo Implement this function. */

Your standard C++ library does not have complete c++0x (now c++1x?) support. 您的标准C ++库没有完整的c ++ 0x(现在是c ++ 1x?)支持。 Try using Boost's code. 尝试使用Boost的代码。 See also this answer . 另见这个答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM