需要使用带有wstring的regex_replace协助

505*_*Z06 4 c++ stl

我想使用regex_replace,就像使用string/c-string(3)版本链接到此处的示例一样:http://www.cplusplus.com/reference/regex/regex_replace/

问题是我不了解模板和正则表达式类,以便在每个示例中使用regex_replace,但是使用宽字符串.我看到了wregex,但我没有看到我如何使用它.

我的想法是取一个字符串regex_ {13E008E3-EEE7-4AC3-B9F1-E353DB67EDFD}并将其转换为status_ {13E008E3-EEE7-4AC3-B9F1-E353DB67EDFD}

wstring statusDataName;
wstring key              = wstring(L"regex_");
wstring repl             = wstring(L"status_");
TCHAR dataName[MAX_STR]  = {0};
statusDataName = regex_replace(wstring(dataName), key,  repl);
Run Code Online (Sandbox Code Playgroud)

错误C2784:'std :: basic_string <_Elem,std :: char_traits <_Elem>,std :: allocator <_Other >> std :: regex_replace(const _Elem*,const std :: basic_regex <_Elem,_RxTraits>&,const _Elem*,std :: regex_constants :: match_flag_type)':无法从'std :: basic_string,std :: allocator>中推断'const _Elem*'的模板参数错误C2784:'std :: basic_string <_Elem,std :: char_traits <_Elem>,std :: allocator <_Other >> std :: regex_replace(const _Elem*,const std :: basic_regex <_Elem,_RxTraits>&,const std :: basic_string <_Elem,_Traits1,_Alloc1>&,std: :regex_constants :: match_flag_type)':无法从'std :: basic_string,std :: allocator>'中推断'const _Elem*'的模板参数错误C2784:'std :: basic_string <_Elem,_Traits1,_Alloc1> std :: regex_replace(const std :: basic_string <_Elem,_Traits1,_Alloc1>&,const std :: basic_regex <_Elem,_RxTraits>&,const _Elem*,std :: regex_constants :: match_flag_type)':无法推断'const的模板参数std :: basic_regex <_Elem,_RxTraits>&'from'std :: wstring'错误C2784:'std :: basic_string <_Elem,_Traits1,_Alloc1> std :: regex_replace(const std :: basic_string <_Elem,_Traits1,_Alloc1>&,const std :: basic_regex <_Elem,_RxTraits>&,const std :: basic_string <_Elem ,_Traits2,_Alloc2>&,std :: regex_constants :: match_flag_type)':无法推断'const std :: basic_regex <_Elem,_RxTraits>&'来自'std :: wstring'的模板参数错误C2780:'_ _OutIt std: :regex_replace(_OutIt,_BidIt,_BidIt,const std :: basic_regex <_Elem,_RxTraits>&,const _Elem*,std :: regex_constants :: match_flag_type)':预期有6个参数 - 3提供错误C2780:'_ OutTy*std :: regex_replace(_OutTy(&)[_ OutSize],_ BidIt,_BidIt,const std :: basic_regex <_Elem,_RxTraits>&,const std :: basic_string <_Elem,_Traits,_Alloc>&,std :: regex_constants :: match_flag_type)':期望6个参数 - 3个提供错误C2780:'_OutIt std :: regex_replace(_OutIt,_BidIt,_BidIt,const std :: basic_regex <_Elem,_RxTraits>&,const std :: basic_string <_Elem,_Traits,_Alloc>&,std: :regex_constants :: match_flag_type)':期望6个参数 - 3 提供

我怎样才能解决这个问题?

fgh*_*ghj 13

工作变体:

#include <string>
#include <regex>
#include <iostream>

using std::wstring;

int main()
{
    wstring dataName = L"regex_{13E008E3-EEE7-4AC3-B9F1-E353DB67EDFD} ";

    wstring key              = wstring(L"regex_");
    wstring repl             = wstring(L"status_");
    wstring statusDataName = std::regex_replace(dataName, std::wregex(key),  repl);
    std::wcout << statusDataName << L"\n";
}
Run Code Online (Sandbox Code Playgroud)