我正在用C++編寫一個程序,它必須處理unicode字符。 主要的問題是我使用的算法,我需要通過焦炭解析我的S/wstrings 字符:使用wstring和wcout沒有得到預期的輸出
std::wstring word = L"Héllo"
for (auto &e : word)
// doing something with e
但是,如果我運行此:
std::wstring word = L"Héllo"
for (auto &e : word)
std::wcout << e << std::endl;
我得到這樣的輸出:
H
?
l
l
o
我做錯了什麼?
請注意,當使用std::wcout << word;
時,請正確打印word
。
編輯@Ben福格特
這裏是出與std::wcout << std::hex << std::setw(4) << (int)e << L" " << e << L'\n';
:
48 H
e9 �
6c l
6c l
6f o
你呢r控制檯支持unicode? – NathanOliver
觀察:不處理代理對,因爲未知字符只有一行輸出。 –
它的確如此,因爲當我打印std :: wcout中的所有字符串時,我可以看到'é' – LightMan