1

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.

H'H
  • 1,638
  • 1
  • 15
  • 39

1 Answers1

0

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.

Community
  • 1
  • 1
Ken Y-N
  • 14,644
  • 21
  • 71
  • 114
  • Using `TCHAR` is terrible advice. Why would you prefer that over `wchar_t`? Windows 98 support? Because that is the only valid reason. – rubenvb Nov 09 '16 at 13:32
  • @rubenvb OK, I deleted my "terrible advice", but I thought leaving the option of compiling either for single byte or double byte was sound. I've not done any Windows for ages, so are single-byte text strings effectively deprecated? – Ken Y-N Nov 09 '16 at 13:37
  • @KenY-N Thanks for your answer, I have got similar problem for "no operator found which takes a right-hand operand of type const std::basic_string", any idea? (is it better to post another question?) changing compiler is driving me crazy. – H'H Nov 09 '16 at 13:40
  • 1
    @Ken There is just no reason to not use the `W` version of all API functions. Especially if you are already using it. – rubenvb Nov 09 '16 at 13:56