如何在 C++ 中打印这个“█”特殊字符?

问题描述 投票:0回答:2

我想在 visual studio (c++) 中打印这个特殊字符 █ 但我得到“?” . 我写的对应代码:

bool b[5][3] = { { true,true,true },{ true,false,true },{ true,false,true }, 
                 { true,false,true },{ true,true,true } };
    system("color 0A");
    for (int i = 0; i < 5; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            if (b[i][j])
            {
                gotoXY(3 + j, 5 + i);
                cout << "█";
            }
        }
        cout << endl;
    }
c++ special-characters
2个回答
3
投票

你应该使用宽输出:

#include <iostream>

#include <stdio.h>
#include <fcntl.h>
#include <io.h>

int main()
{
    ::_setmode(::_fileno(stdout), _O_U16TEXT);
    ::std::wcout << L"█" << ::std::flush;
    return 0;
}

此外,如果您打算使用伪图形,那么您可能需要为控制台选择一些像素字体,以便在没有抗锯齿和间隙的情况下呈现符号。


2
投票

试一试:

std::cout <<"\u2588";

█ 统一码:U+2588

© www.soinside.com 2019 - 2024. All rights reserved.