I am trying to read a UTF-8 text file in Visual C++ 2010 using only the standard library and not Boost or Windows APIs. I define the locale as:
std::locale utf8_locale(std::locale(), new std::codecvt_utf8<wchar_t>);
but this results in the following compiler error:
error C2661: 'std::locale::facet::operator new' : no overloaded function takes 3 arguments
error C2664: 'std::locale::locale(const char *,std::locale::category)' : cannot convert parameter 1 from 'std::locale' to 'const char *'
The error is occures in debug mode when the code is used in the file that micrsoft Visual c++ provided below macro is placed.
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
to get rid of this error the #define new DEBUG_NEW
should be commented out or the code should be implemented in another file which does not have the above macro.
This bug for Visual c++ 2010 is mentioned here http://connect.microsoft.com/VisualStudio/feedback/details/683483/mfc-c-fails-to-compile-use-of-codecvt-utf8-in-debug-configuration
FYI, another work around is to just write
std::locale utf8(std::locale(), ::new std::codecvt_utf8<wchar_t>);
That will force the compiler to use the global new, instead of the locale new
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