且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 C++ 中输出 unicode 框绘图?

更新时间:2022-11-08 21:20:26

如果模式设置正确,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:

┏━━━━━━━━━━━━━━━━━┓
┃