如何在 C++ 中输出 unicode 框绘图? [英] How to output unicode box drawing in C++?
问题描述
抱歉,这听起来很简单,但我正在尝试使用 https://en.wikipedia.org/wiki/Box-drawing_character 使用下面的代码
Sorry for what may sound simple, but I am trying to draw just a simple box in Visual Studio 2017 using the unicode characters from https://en.wikipedia.org/wiki/Box-drawing_character using the code below
#include <iostream>
using namespace std;
int main()
{
cout << "┏━━━━━━━━━━━━━━━━━┓" << endl;
cout << "┃" << endl;
等等...
但是,每当我运行它时,上面的所有代码都只是输出为 ?应该有一条线的地方.
However, whenever I run it all of the above code simply outputs as a ? wherever there should be a line.
那么是否可以将这样的代码直接输出到控制台,或者对于每个字符我是否必须为每个字符编写数值?
So is it possible to output code like this directly to the console or for each character do I have to write the numeric values for each character?
推荐答案
如果模式设置正确,Windows 控制台应用程序可以将宽字符串 (L"..."
) 直接输出到终端.注意 wcout
的使用.以 UTF-8 编码保存以下源代码:
Windows console apps can output wide strings (L"..."
) directly to the terminal if the mode is set correctly. Note the use of wcout
as well. Save the following source in UTF-8 encoding:
#include <iostream>
#include <io.h>
#include <fcntl.h>
using namespace std;
int main()
{
_setmode(_fileno(stdout), _O_U16TEXT);
wcout << L"┏━━━━━━━━━━━━━━━━━┓" << endl;
wcout << L"┃" << endl;
}
用cl/EHsc/utf-8 test.cpp"编译.输出为:
Compile with "cl /EHsc /utf-8 test.cpp". Output is:
┏━━━━━━━━━━━━━━━━━┓
┃
这篇关于如何在 C++ 中输出 unicode 框绘图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!