在C ++中打印国际象棋unicode字符,并使字符变为方形 [英] Print chess unicode characters in C++, and make characters square sized

查看:138
本文介绍了在C ++中打印国际象棋unicode字符,并使字符变为方形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问一下用C ++在控制台窗口中编写国际象棋unicode字符的最简单方法是什么? (♙♘♗♖♕♔♟♞♝♜♛♚)它们是unicode中其他符号块的一部分。 https://en.wikipedia.org/wiki/Chess_symbols_in_Unicode

I'd like to ask what's the simplest way of writing the chess unicode characters in a console window in C++? (♙♘♗♖♕♔♟♞♝♜♛♚) They are part of the "Miscellaneous Symbols" block in unicode. https://en.wikipedia.org/wiki/Chess_symbols_in_Unicode

我也想打印正方形的字符,现在我的国际象棋棋盘不是正方形,因为每个字符都是矩形而不是正方形。

I also want to print characters with square size, right now my chess board is not square, because each character is a rectangle and not a square.

能够在国际象棋棋盘下面写普通的非正方形字符也很好,但这可能是不可能的吗?要在同一控制台窗口中混合使用不同的字体/格式?

It'd also be good to be able to write with ordinary non-square characters below the chess board, but that might be impossible? To mix different fonts/formattings in the same console window?

好,谢谢! :)

推荐答案

问题的第一部分输出这些字符,取决于平台。 Linux控制台通常使用UTF-8,如果是这种情况,您可以将字符编码为UTF-8并将其写入标准输出。在Windows上,您可以使用控制台API( WriteConsole 函数):

The first part of your question, outputting those characters, is platform-dependent. Linux consoles often use UTF-8, if that is the case you can encode the characters as UTF-8 and write them to standard output. On Windows you can use the Console API (the WriteConsole function):

HANDLE handle = GetStandardHandle(STD_OUTPUT_HANDLE);
DWORD written = 0;
// explicitly call the wide version (which always accepts UTF-16)
WriteConsoleW(handle, L"\u2658", 1, &written, NULL);

一个难以解决的警告是,您需要一种包含这些字符的控制台字体。

One caveat which is hard to work around is that you need a console font containing those characters.

要获取正方形单元格,这取决于控制台呈现文本的方式的许多细节。如果使用字体替换,则文本实际上将不会被等宽。

For getting square cells, this is dependent on a lot of specifics about the way the console renders text. If it uses font substitution, then there is a chance the text will not actually be monospaced.

现在,如果您有一个控制台字体,这些字符,以及 if 该字体是等距的,那么您可以通过在字符之间添加一些间距来绘制方板。您可以使用 U + 258C —左半块之类的块元素来绘制棋盘:▌♘▐█▌ ▐

Now, if you have a console font with these characters, and if that font is monospaced, then you may be able to draw a square board by adding some spacing between the characters. You can use block elements like U+258C — LEFT HALF BLOCK to draw the chequerboard: ▌♘▐█▌ ▐.

这篇关于在C ++中打印国际象棋unicode字符,并使字符变为方形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆