为了确定 C++ 是否适合我的项目,我想测试 UTF-8 功能。根据引用资料,我建立了这个例子:
#include <string>
#include <iostream>
using namespace std;
int main() {
wstring str;
while(getline(wcin, str)) {
wcout << str << endl;
if(str.empty()) break;
}
return 0;
}
但是当我输入一个 UTF-8 字符时,它会出错:
$ > ./utf8
Hello
Hello
für
f
$ >
它不仅不打印ü
,而且还立即退出。 gdb
告诉我没有崩溃,而是正常退出,但我觉得很难相信。
最佳答案
不要在 Linux 上使用 wstring。
看看第一个答案。我相信它会回答您的问题。
- When I should use std::wstring over std::string?
On Linux? Almost never (§).
On Windows? Almost always (§).
关于c++ - 在 C++ 中处理 UTF-8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8513249/