所以我可以将粘贴象棋子这样的unicode字符直接复制到终端(我正在使用debian jessie linux),但是每当我编写c++代码来做到这一点时,我都会得到这些。
这是我的代码
enter code here
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
using namespace std;
int main()
{
setlocale(LC_ALL,"");
wchar_t piece='♗';
wcout<<piece;
}
我尝试使用字符的十六进制或十进制代码,但是它不起作用
我还使用vim进行编辑,并且在键入时确实显示了字符。
最佳答案
没有关于wchar_t应该使用哪种编码的规范。我需要使用mbstowcs函数来转换该字符。像这样,例如:
#include <iostream>
#include <clocale>
#include <cstdlib>
using namespace std;
int main(void) {
setlocale(LC_ALL, "");
wchar_t piece;
mbstowcs(&piece, "♗", 1);
wcout << piece << endl;
return 0;
}
假设您的源文件编码与语言环境的编码匹配。
关于c++ - 即使我可以直接写它们,也无法输出unicode字符,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36763891/