我有带有西里尔字母的 wstring。我需要从它那里得到一封信。 我发现只有这样:
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 - 如果您在其他地方,您可以通过阅读宏链接及其随附的 Surrogates and Supplementary Characters 自行检查。文档。
关于c++ - 我如何从西里尔字符串中获取一个字符 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28849976/