"cout"无法使用汉字

Eld*_*rry 2 c++ cout character

我的代码就像这些一样简单:

#include <iostream>
using namespace std;
//Some codes here...
bool somefunction(){
    cout<<"???";
    return false;
}
Run Code Online (Sandbox Code Playgroud)

这就是我得到的:

error C2143: syntax error: missing ';' before 'return';
error C2001: newline is constant;

而且,如果我"???"换成像"细胞"这样的英文版,那就完美了;

nne*_*neo 5

编译器错误表明您的编译器不支持源代码中的Unicode字符.你必须逃避它们,使用宽字符常量,并且wcout:

wcout << L"\x5355\x5143\x683c";
Run Code Online (Sandbox Code Playgroud)

如果需要输出特定编码的字符(例如gb2312),请在字符串文字中使用该编码:

cout << "\xb5\xa5\xd4\xaa\xb8\xf1"; // string encoded with GB2312
Run Code Online (Sandbox Code Playgroud)