簡體   English   中英

Visual C ++ 2010中的UTF-8語言環境

[英]UTF-8 locale in Visual C++ 2010

我試圖只使用標准庫而不是Boost或Windows API在Visual C ++ 2010中讀取UTF-8文本文件。 我將語言環境定義為:

std::locale utf8_locale(std::locale(), new std::codecvt_utf8<wchar_t>);

但這會導致以下編譯器錯誤:

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 *'

當代碼用於放置下面提供的微軟Visual C ++文件時,調試模式中會出現錯誤。

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

為了擺脫這個錯誤,應該注釋#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

僅供參考,另一項工作就是寫作

std::locale utf8(std::locale(), ::new std::codecvt_utf8<wchar_t>);

這將迫使編譯器使用全局new,而不是locale new

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM