首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Windows控制台中以红色和黑色显示这些卡片套装符号?

如何在Windows控制台中以红色和黑色显示这些卡片套装符号?
EN

Stack Overflow用户
提问于 2020-09-30 04:00:31
回答 3查看 143关注 0票数 1

我有一系列的纸牌套装。

代码语言:javascript
复制
char *suits[4] = {"♥","♦","♣","♠"};

为了能够在Windows控制台中看到它们,我必须这样写:

代码语言:javascript
复制
SetConsoleOutputCP(65001);

有没有办法设置这些西装的颜色?

具体来说,红色代表♥和♦,黑色代表♣和♠。

EN

回答 3

Stack Overflow用户

发布于 2020-09-30 04:35:16

由于PowerShell已标记,因此您可以使用Write-Host将这些带有颜色的符号打印到控制台

代码语言:javascript
复制
$suits = "♥","♦","♣","♠"
Write-Host $($suits[0..1]) -ForegroundColor Red; Write-Host $($suits[2..3]) -ForegroundColor Black

在cmd shell中运行它,就意味着调用PowerShell.exe来运行以下代码:

代码语言:javascript
复制
powershell.exe -command "$suits = '♥','♦','♣','♠'; Write-Host $($suits[0..1]) -ForegroundColor Red; Write-Host $($suits[2..3]) -ForegroundColor Black"
票数 0
EN

Stack Overflow用户

发布于 2020-09-30 05:06:52

尝尝这个!

您看不到它们的原因是,通常cmd控制台不支持杂项符号(这是Unicode标准中的特殊符号)。但是,如果直接在命令提示符下运行,则可以看到它们。您可以尝试使用此代码,也可以在此处阅读_setmode && wprintf文档!‍‍♥

代码语言:javascript
复制
// crt_setmodeunicode.c
// This program uses _setmode to change
// stdout to Unicode. Cyrillic and Ideographic
// characters will appear on the console (if
// your console font supports those character sets).

#include <fcntl.h> //file control library
#include <io.h>  //IO parameter   
#include <stdio.h>

int main(void) {
    _setmode(_fileno(stdout), _O_U16TEXT); //We're recibing the stdout file descriptor and then we change
                                           //it to the Unicode translation.
    wprintf(L" CLUB: \x2663 \n\n DIAMOND: \x2666 \n\n HEART: \x2665 \n\n SPADES: \x2660\n");
    return 0;
}

https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/setmode?view=vs-2019

  • wprintf文档:http://www.cplusplus.com/reference/cwchar/wprintf/

  • _setmode文档
票数 0
EN

Stack Overflow用户

发布于 2020-09-30 06:04:00

用于Powershell的

代码语言:javascript
复制
$suits = [char]0x2665,[char]0x2666,[char]0x2663,[char]0x2660;
0..4|% {if ($_ -le 1){ 
    write-host $suits[$_] -ForegroundColor Red –NoNewline;
     } else { write-host $suits[$_] -ForegroundColor Black –NoNewline}}

用于cmd的

代码语言:javascript
复制
powershell -nop -c $suits=[char]0x2665,[char]0x2666,[char]0x2663,[char]0x2660;0..4^|? ^{if ($_ -le 1) ^{write-host $suits[$_] -ForegroundColor Red -NoNewline^} else ^{write-host $suits[$_] -ForegroundColor Black -NoNewline^}^}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64126796

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档