0
#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;

}

Compiler says:

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
    Sorry, but what is the question? – Skurmedel May 21 '11 at 14:30
  • sry, I tried to compile it, but It returns errors about template "const std::tr1::basic_regex<_Elem,wchar_t> &" from "const std::tr1::wregex", – cynicalanlz May 21 '11 at 14:34
  • so the question is - how to make it work, with those strings, and display results properly, I've tried the regex_replace(line,wr,line2), without the - it returns some random info like "00423DA4" – cynicalanlz May 21 '11 at 14:35
  • 1
    Can you copy the error? Just saying something general about it won't help anyone help you. – Boaz Yaniv May 21 '11 at 14:37
  • have added em to the question – cynicalanlz May 21 '11 at 14:42
  • Ok, basically regex_replace shouldn't compile, because the first template argument is not a the character type, but the traits class. You shouldn't need to specify it. I still don't know why you don't get a replacement when you don't use the wchar_t. – Boaz Yaniv May 21 '11 at 14:42
  • I'm sorry- this site is in English. I can't read those errors. – Puppy May 21 '11 at 14:43
  • Heh, never knew VC++ can spit out erros in Russian. @DeadMG: It probably means something like "Couldn't decide(?) template argument X from Y". The reason is that the traits argument (RXTraits) was supplied with wchar_t. – Boaz Yaniv May 21 '11 at 14:46
  • yes, I've translated those to english .. – cynicalanlz May 21 '11 at 14:49

1 Answers1

2

Partial answer:

You should use regex_repalce this way:

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

i.e., without the wchar_t. The first argument is for the Element Traits class, which you'd only rarely want to modify.

Edit

I've checked your code with VC++ 2010. Changing the line as I specified allowed the code to compile, and return the result as expected. Can you try it again?

Boaz Yaniv
  • 6,334
  • 21
  • 30
  • Yes, I've found out that made some syntactic mistakes with locale in the function, I've used to fill the line1 up, removing fixed the problem. – cynicalanlz May 21 '11 at 15:06