How can I print this"█" special character in C++?

Viewed 997

I want to print this special character █ in visual studio (c++) but I get "?" . The corresponding code that I wrote:

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;
    }
2 Answers

You should use wide output:

#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;
}

Also if you are going to use pseudo graphics then you may want to select some pixel font for console so symbols will be rendered without antialiasing and gaps.

Try out: std::cout <<"\u2588";

█ unicode: U+2588

Related