2010-09-15 66 views
2

我試圖在我的C++應用程序中插入Unicode字符U+2022(bullet )。C++ Unicode Bullet Point

我無法弄清楚如何轉換的是U + 2022爲的std :: string構造函數中使用char /串...

char bullet = char(0x2022); 
mPassword.SetText(std::string(mText.length(), bullet)); 

這一個不工作。希望你能幫助!

由於
opatut

+1

的【如何可能重複的專業我可以嵌入unicode字符串常量在源文件?](http://stackoverflow.com/questions/442735/how-can-i-embed-unicode-string-constants-in-a-source-file) – 2010-09-15 17:10:39

回答

4

Unicode字符的類型是wchar_t(參照C++標準的§ 2.13.4)。你可以按如下方式使用它:

wchar_t bullet = L'\x2022'; 

在弦,它就會像這樣:

std::wstring str_w_bullet(L"some text with \x2022"); 
+0

應該指出根據您在Linux中的語言環境,std:string在技術上是t作爲一系列UTF-8編碼單元進行處理,因此它能正確處理unicode。然而,我不知道如何設置它們中的任何一個,如果你想要的不是ASCII,而是想在代碼中設置它而不是讀取已經是unicode的東西(你可能必須弄清楚每個代碼是什麼單位而不是一次設置整個代碼點)。但是,在Windows上,我認爲你確實必須使用std :: wstring。 – 2010-09-15 17:29:11

+0

我仍然有問題。我只是沒有得到我的輸出的重點。 std :: wcout的輸出引號(「) – opatut 2010-09-15 17:53:30

+1

問題出在控制檯。檢查[this](http://stackoverflow.com/questions/2492077/output-unicode-strings-in-windows-console-app)問題if你使用Windows。 – 2010-09-15 18:03:11

1

使用std::wstring這是相同std::stringwchar_t