
Hi, I'm trying to use Unicode with Regex in an MFC app. The preprocessor variable UNICODE is defined. But I obtain an error on the line : regex_search(sText, oResults, pRegExp); error C2665: none of the 4 overloads can convert parameter 1 from type 'class CString' sText is a CString which has a "const wchar_t*" operator. The problem is why doesn't the regex_search prototype require a "const wchar_t*" when UNICODE is defined ? Thanks. Fred (I read the documentation, but maybe I missed something...)

I'm trying to use Unicode with Regex in an MFC app. The preprocessor variable UNICODE is defined. But I obtain an error on the line :
regex_search(sText, oResults, pRegExp); error C2665: none of the 4 overloads can convert parameter 1 from type 'class CString'
sText is a CString which has a "const wchar_t*" operator. The problem is why doesn't the regex_search prototype require a "const wchar_t*" when UNICODE is defined ?
You did, use sText.c_str() to get a const wchat_t*, otherwise there are too many overloaded forms of the function for the conversion to be found automatically. John Maddock http://ourworld.compuserve.com/homepages/john_maddock/index.htm

John Maddock wrote:
I'm trying to use Unicode with Regex in an MFC app. The preprocessor variable UNICODE is defined. But I obtain an error on the line :
regex_search(sText, oResults, pRegExp); error C2665: none of the 4 overloads can convert parameter 1 from type 'class CString'
sText is a CString which has a "const wchar_t*" operator. The problem is why doesn't the regex_search prototype require a "const wchar_t*" when UNICODE is defined ?
You did, use sText.c_str() to get a const wchat_t*, otherwise there are too many overloaded forms of the function for the conversion to be found automatically.
I tried the "const wchar_t*" operator : regex_search((const wchar_t*) sText, oResults, pRegExp); but the problem is not here. VC++6 wrote : error C2664: '__thiscall boost::reg_expression<char,class boost::regex_traits<char>,class boost::detail::allocator_adapter<char,class boost::detail::simple_alloc> >::boost::reg_expression<char,class boost::regex_traits<char>,class boost::detail::allocator_adapter<char,class boost::detail::simple_alloc> >(const class boost::detail::allocator_adapter<char,class boost::detail::simple_alloc> &)' : cannot convert parameter 1 from 'const unsigned short *' to 'const class boost::detail::allocator_adapter<char,class boost::detail::simple_alloc> &' Reason: cannot convert from 'const unsigned short *' to 'const class boost::detail::allocator_adapter<char,class boost::detail::simple_alloc>' No constructor could take the source type, or constructor overload resolution was ambiguous You see that the reg_expression prototype contains "char"s and not "wchar_t"s. Are you sure that the only thing to do to use UNICODE is to put a #define UNICODE (I put it in my stdafx.h and in my project settings)? Thanks. Fred

I'm trying to use Unicode with Regex in an MFC app. The preprocessor variable UNICODE is defined. But I obtain an error on the line :
regex_search(sText, oResults, pRegExp); error C2665: none of the 4 overloads can convert parameter 1 from type 'class CString'
sText is a CString which has a "const wchar_t*" operator. The problem is why doesn't the regex_search prototype require a "const wchar_t*" when UNICODE is defined ?
You did, use sText.c_str() to get a const wchat_t*, otherwise there are too many overloaded forms of the function for the conversion to be found automatically.
I tried the "const wchar_t*" operator : regex_search((const wchar_t*) sText, oResults, pRegExp); but the problem is not here. VC++6 wrote : error C2664: '__thiscall boost::reg_expression<char,class boost::regex_traits<char>,class boost::detail::allocator_adapter<char,class boost::detail::simple_alloc> >::boost::reg_expression<char,class boost::regex_traits<char>,class boost::detail::allocator_adapter<char,class boost::detail::simple_alloc> >(const class boost::detail::allocator_adapter<char,class boost::detail::simple_alloc> &)' : cannot convert parameter 1 from 'const unsigned short *' to 'const class boost::detail::allocator_adapter<char,class boost::detail::simple_alloc> &' Reason: cannot convert from 'const unsigned short *' to 'const class boost::detail::allocator_adapter<char,class boost::detail::simple_alloc>' No constructor could take the source type, or constructor overload resolution was ambiguous
You see that the reg_expression prototype contains "char"s and not "wchar_t"s. Are you sure that the only thing to do to use UNICODE is to put a #define UNICODE (I put it in my stdafx.h and in my project settings)?
Sorry, let me try again: the only effect that defining UNICODE has on the regex lib is on the definition of the POSIX C API functions. All the template classes and functions remain unchanged. So you need to be using boost::wregex not boost::regex for your regular expressions. John Maddock http://ourworld.compuserve.com/homepages/john_maddock/index.htm
participants (2)
-
Fr�d�ric Mayot
-
John Maddock