H'H H'H - 29 days ago 14
C++ Question

errors C2784, C2672 and C2664 in Visual studio 2015

I have following lines in visual studio 2015. It used to be compiled without error in visual studio 2013.

const std::basic_regex<wchar_t> e(_T("([eE][-+])(0)(\\d{2})"));
io_string = std::regex_replace(io_string, e, _T("$1$3"));


the error is:

error C2664: 'std::basic_regex>::basic_regex(std::basic_regex> &&) noexcept': cannot convert argument 1 from 'const char [21]' to 'const wchar_t *'

error C2672: 'std::regex_replace': no matching overloaded function found
4>

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::string_t'

I know this issue is coming from change tchar.h. Any suggestion for resolving them. I also use CMake for project configuration and the project is running on windows 10.

Answer

Assuming you don't want to change your code, you need to ensure that your code is building for Unicode, so pass -D_UNICODE to the compiler. This post suggests:

ADD_DEFINITIONS(-DUNICODE)
ADD_DEFINITIONS(-D_UNICODE)

And this one illustrates how to enable Unicode through the GUI.