使用 中的 regex_replace 函数时出错

发布于 2024-09-29 00:20:25 字数 1610 浏览 4 评论 0 原文

#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 copiler 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
#include <string>
#include <tr1/regex>

#include "TextProcessing.h"

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

人间☆小暴躁 2024-10-06 00:20:25

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

/** @todo Implement this function. */

Yup, in my g++ include files I also see that regex_replace is declared and not defined. For me, it's in the file /usr/include/c++/4.4.4/tr1_impl/regex . Just above the declaration is a Doxygen comment section which includes:

/** @todo Implement this function. */
陌伤ぢ 2024-10-06 00:20:25

您的标准 C++ 库没有完整的 c++0x(现在是 c++1x?)支持。尝试使用 Boost 的代码。另请参阅此答案

Your standard C++ library does not have complete c++0x (now c++1x?) support. Try using Boost's code. See also this answer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文