c++ - 使用 <tr1/regex> 中的 regex_replace 函数时出错

标签 c++ regex gcc tr1

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

我使用的是 mingw gcc 编译器 4.5.0 版本。

我有以下错误:

%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

最佳答案

是的,在我的 g++ 包含文件中,我还看到 regex_replace 已声明但未定义。对我来说,它在文件/usr/include/c++/4.4.4/tr1_impl/regex 中。声明的正上方是 Doxygen 注释部分,其中包括:

/** @todo Implement this function. */

关于c++ - 使用 <tr1/regex> 中的 regex_replace 函数时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3983131/

相关文章:

c++ - 嵌套结构属性继承

java - 为什么正则表达式最后少匹配一个字符?

javascript - 在 Javascript 正则表达式匹配中查找索引

c - 如何在 C 语言中对性能优化进行单元测试?

c - GCC 编译器、插件和结构

c++ - 在 VIsual Studio 错误 NewFolder 中运行 MFC C++ 代码不是有效的工作目录

c++ - SWIG C++ Python : wrapping int by reference or pointer

c - C99 'restrict' 关键字的实际用法?

c++ - 使用继承时类的大小是多少?

javascript - 如何捕获两个(编号)标记之间的所有内容,包括换行符?