TR1 regex_replace с wstring в VS2010? - PullRequest
0 голосов
/ 21 мая 2011
#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"

1 Ответ

2 голосов
/ 21 мая 2011

Частичный ответ:

Вы должны использовать regex_repalce следующим образом:

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

т.е. без wchar_t.Первый аргумент относится к классу Element Traits, который вы редко захотите изменить.

Edit

Я проверил ваш код с VC ++ 2010. Изменение строки, как я указал, позволилокод для компиляции и возврата результата, как и ожидалось.Вы можете попробовать это снова?

...