如何使用wstring和wcout在Xcode中输出中文单词?

Sid*_*ang 2 c++ macos xcode

我尝试在Xcode 4.2中运行代码:

int main(int argc, const char * argv[])
{
    locale loc("chs");
    locale::global(loc);

    wstring text(L"??");
    wcout << text << endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我收到错误"Thread 1:signal SIGABRT".

你能告诉我为什么会发生错误,或者如何使用wstring和wcout输出中文单词?

Mah*_*dsi 6

你没有.与其他Unix系统一样,Mac使用UTF8,而Windows使用"Unicode"(UTF-16).

您可以通过使用打印非常清楚在Mac string和cout,而不是wstring和wcout.

附录

这个样本效果很好.使用g ++编译并按原样运行.

#include <string>
#include <iostream>

using namespace std;

int main(int arg, char **argv)
{
    string text("??");
    cout << text << endl;

    return 0;
}
Run Code Online (Sandbox Code Playgroud)