Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

print a filled square in console

Tags:

c++

linux

ascii

I need to print a filled square in Linux terminal using my C++ program (1cm x 1cm size). I tried to use ASCII 254 (■), but in terminal it print as garbage character. I'm not sure how to print extended ASCII character using c++. Here are two methods I have tried to print extended ASCII. but not succeed.

First method

for(int i=128; i< 255; i++ )
{
 std::cout << static_cast<char>(i) << std::endl;
}

Second method

unsigned char temp = 'A'
for(int i=65; i< 255; i++ )
{
 std::cout << temp++ << std::endl;
 std::wcout << temp << std::endl;
}

Any suggestion or alternative Idea?

like image 669
Nayana Adassuriya Avatar asked Oct 18 '14 09:10

Nayana Adassuriya


1 Answers

Try using the unicode cout << "\u25A0";

http://www.fileformat.info/info/unicode/category/So/list.htm

like image 56
Jens A. Koch Avatar answered Sep 20 '22 21:09

Jens A. Koch