gpt4 book ai didi

c++ - 在 VS2010 中用 wstring 替换 TR1 regex_replace?

转载 作者:行者123 更新时间:2023-11-28 03:49:18 34 4
gpt4 key购买 nike

#include <iostream>
#include <string>
#include <regex>
#include <ios>
#include <locale>

using namespace std;

int main ()
{

const wstring wstr(L"<(.|\\n)*?>");
static const wregex wr(wstr);
wstring line (L"<tag>Random text<tag>");
wstring line2 (L"");
wcout << regex_replace<wchar_t>(line,wr,line2) << endl;

}

编译器说:

ClCompile:
html.cpp
c:\users\usr\documents\visual studio 2010\projects\html\html\html.cpp(34): error C2784: std::basic_string<_Elem> std::tr1::regex_replace(const std::basic_string<_Elem> &,const std::tr1::basic_regex<_Elem,_RxTraits> &,const std::basic_string<_Elem> &,std::tr1::regex_constants::match_flag_type): not able to output argument template "const std::tr1::basic_regex<_Elem,wchar_t> &" from "const std::tr1::wregex"
c:\program files\microsoft visual studio 10.0\vc\include\regex(2739): look to typedef "std::tr1::regex_replace"
c:\users\usr\documents\visual studio 2010\projects\html\html\html.cpp(34): error C2784: std::basic_string<_Elem> std::tr1::regex_replace(const std::basic_string<_Elem> &,const std::tr1::basic_regex<_Elem,_RxTraits> &,const std::basic_string<_Elem> &,std::tr1::regex_constants::match_flag_type): not able to output argument template for "const std::tr1::basic_regex<_Elem,wchar_t> &" from "const std::tr1::wregex"
c:\program files\microsoft visual studio 10.0\vc\include\regex(2739): look to typedef of "std::tr1::regex_replace"
c:\users\usr\documents\visual studio 2010\projects\html\html\html.cpp(34): error C2784: std::basic_string<_Elem> std::tr1::regex_replace(const std::basic_string<_Elem> &,const std::tr1::basic_regex<_Elem,_RxTraits> &,const std::basic_string<_Elem> &,std::tr1::regex_constants::match_flag_type): not able to output argument template for "const std::tr1::basic_regex<_Elem,wchar_t> &" from "const std::tr1::wregex"
c:\program files\microsoft visual studio 10.0\vc\include\regex(2739): look to typedef "std::tr1::regex_replace"

最佳答案

部分答案:

你应该这样使用regex_repalce:

wcout << regex_replace(line,wr,line2) << endl;

即,没有 wchar_t。第一个参数用于 Element Traits 类,您很少想修改它。

编辑

我已经使用 VC++ 2010 检查了您的代码。按照我指定的方式更改行允许代码编译,并按预期返回结果。你能再试一次吗?

关于c++ - 在 VS2010 中用 wstring 替换 TR1 regex_replace?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6082355/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com