I want to use regex_replace like the example linked here using using string/c-string (3) version: http://www.cplusplus.com/reference/regex/regex_replace/
The problem is I don't understand templates and the regex classes well enough to use regex_replace per example, but with a wide string. I saw the wregex, but I'm not seeing how I can use it.
The idea is to take a string regex_{13E008E3-EEE7-4AC3-B9F1-E353DB67EDFD} and turn it into 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);
error 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)' : could not deduce template argument for 'const _Elem *' from 'std::basic_string,std::allocator>' error 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)' : could not deduce template argument for 'const _Elem *' from 'std::basic_string,std::allocator>' error 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)' : could not deduce template argument for 'const std::basic_regex<_Elem,_RxTraits> &' from 'std::wstring' error 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)' : could not deduce template argument for 'const std::basic_regex<_Elem,_RxTraits> &' from 'std::wstring' error C2780: '_OutIt std::regex_replace(_OutIt,_BidIt,_BidIt,const std::basic_regex<_Elem,_RxTraits> &,const _Elem *,std::regex_constants::match_flag_type)' : expects 6 arguments - 3 provided error 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)' : expects 6 arguments - 3 provided error 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)' : expects 6 arguments - 3 provided
How can I fix this?
Working variant:
#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";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With