为了确定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
告诉我没有崩溃,只是正常退出,但我很难相信。
string
、cin
、cout
正常工作,但在这里不适用于w...
版本,我怀疑他们想要UTF-32(或16?)。 - Daniel Fischer