c++ 无法输出 unicode 字符,即使我可以直接编写它们
c++ Unable to output unicode characters even though I can write them directly
所以问题是我可以将粘贴的 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;
}
假设源文件编码与区域设置的编码匹配。
奇怪的是,
正常工作的是,将特殊字符放入字符串中,它非常简单,我什至没有想到使用它。
#include<iostream>
using namespace std;
int main()
{
string piece="♗";
cout<<piece;
}
相关文章:
- 是给定代码中的任何更改,以便我可以为问题提供正确的输出
- 有没有办法我可以在 C++ 中使用 if 语句来说明如果一个字符串不是两个名称的 eqal,它会给出一个输出,ATM i
- 我可以将函数的输出参数存储到unique_ptr中吗?
- 了解文件输入和输出,我可以写入文件,但无法从文件打印
- 如何在不将其连接到终端的情况下运行'screen',以便我可以在C++ (qt) 应用程序中捕获输出?
- 有人可以向我解释输出吗?
- 在Qt中:我可以输出到“stdout”吗,就像使用qDebug()输出到“stderr”一样简单
- 我可以将从相机获取的单通道图像输出到 winAppi 窗口中吗?
- 我可以重定向两个子进程的标准输出吗?
- 试图在每次输出后使用一个函数摆脱'0',但不确定我可以返回什么
- 我可以在处理时保持编译器输出的格式
- 我有n个空格,在每个空格中,我可以放置一个数字0到m.编写一个程序来输出所有可能的结果.需要帮助:)
- 如何在 C++ 控制台应用程序中将输入与输出分开?我可以有两个游标吗?
- c++ 无法输出 unicode 字符,即使我可以直接编写它们
- 我可以将输出从 C DLL 重定向到我的 c# log4net 输出吗?
- 我可以让C++预处理器在编译期间发送输出吗?
- 我可以将处理后的视频输出从 PC 上的 OpenCV 流式传输到安卓平板电脑吗?
- 我可以使用 opencv 函数(如 cv::multiply 和 std::vector<cv::Mat> 作为输入和输出参数吗?
- 我可以显示智能感知生成的预处理器输出吗?
- 我可以只获得boost单元测试失败的日志输出吗?