簡體   English   中英

如何從西里爾字符串C ++中獲取一個字符

[英]How can I get one character from cyrillic string c++

我有西里爾字母。 我需要從中收到一封信。 我只是這樣發現的:

wstring line;
wifstream myfile (".../outfile.txt");
if (myfile.is_open())
{
    while (myfile.good())
    {
        getline (myfile,line);
        wstring a = line.substr(0,2); // this gives one first letter
       //....
    }
    myfile.close();
}

有沒有更好的方法來獲取西里爾字母的字母?

如果西里爾文使用UTF-16編碼中的代理對,則不要這樣做:

wstring a = line.substr(0,2);

您可能要考慮做類似以下的事情:

const wchar_t surrogate[] = { line[0], line[1], L'\0' };
const wchar_t non_surrogate[] = { line[0], L'\0' };
const wstring a = IS_SURROGATE_PAIR(surrogate[0], surrogate[1]) ?
                  surrogate :
                  non_surrogate; 

IS_SURROGATE_PAIR宏適用於Windows-如果您在其他地方,則可以通過閱讀宏鏈接及其隨附的“ 代理和補充字符”文檔來進行檢查。

暫無
暫無

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

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