Visual C++ 2010中的UTF-8语言环境

AMC*_*ded 5 c++ utf-8 visual-c++

我试图只使用标准库而不是Boost或Windows API在Visual C++ 2010中读取UTF-8文本文件.我将语言环境定义为:

std::locale utf8_locale(std::locale(), new std::codecvt_utf8<wchar_t>);
Run Code Online (Sandbox Code Playgroud)

但这会导致以下编译器错误:

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 *'
Run Code Online (Sandbox Code Playgroud)

AMC*_*ded 5

当代码用于放置宏下面提供的微软Visual C++文件时,调试模式中会出现错误.

#ifdef _DEBUG
#define new DEBUG_NEW
#endif
Run Code Online (Sandbox Code Playgroud)

为了摆脱这个错误,#define new DEBUG_NEW应该注释掉或者代码应该在另一个没有上述宏的文件中实现.这里提到了Visual c + + +的这个错误http://connect.microsoft.com/VisualStudio/feedback/details/683483/mfc-c-fails-to-compile-use-of-codecvt-utf8-in-debug-configuration